Can I write a method in CMP 2.0 Entity Bean which can retrieve some data from database (ie. is it possible to have a CMP entity bean mapped to a particular table and have a business method in it which retrieve some data from a different table)?

Bozidar Dangubic

You can have CMP Entity Bean map to whichever table you want and you can have business methods in the bean retrieve values from whichever table you want but not ejbStore() ejbLoad()... (i.e not the container callbacks).
CMP does stand for Container managed persistence and therefore you have to let the container do the persistence for you.

But there is nothing to prevent you from declaring a business method in your entity bean that uses JDBC to connect to the database and retrieve data from some other table.
The trouble is that if you business method in populating attributes of the bean itself from a table to which it is not mapped. What can happen in this scenario is app server can figure out that the value of an attribute in your bean has changed and call callback that will retrieve values into the bean attributes from the original table to which CMP attributes are mapped.

I believe that the best solution for you is BMP.

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact