File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Computed value in the entity bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Computed value in the entity bean" Watch "Computed value in the entity bean" New topic
Author

Computed value in the entity bean

Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi all,
I have an entity bean that has for e.g. three fields.
PersonBean
1. Name
2. DOB
3. Age
Now, I have CMP for that bean. The Age is a computed value from the field DOB. So, how do I make the container insert that in the bean on insert/update queries...etc.
This is a specific example but one can have any column in the DB Table to be "derived" (to use database terminology) from other colum/coumns in some defined way.
How to handle this situation using CMP? If we just take the above AGe example we can do some EJB-QL magic (I guess) to compute the Age but what would be a general way of handling this type of scenario?
Regards
Maulin
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
well, probably what we have to do is, compute the derived column and via the session bean (using session facade) call entitybean.setXXX() field just like settting other persistent fields for that computed column we have in the database and so when container calls ejbStore() it automatically stores the computed value in the corresponding column BUT my situation is little different because I have,
- ITEM_COLLECTION entity bean . Dbtable: (ITEM_COLLECTION_ID,ITEMS_INFO1,..., PK(ITEM_COLLECTION_ID))
- ITEM entity bean. Dbtable (ITEM_COLLECTION_ID, ITEM_ID,ITEM_INFO1,..., PK(ITEM_COLLECTION_ID,ITEM_ID))
Now, I want to generate a comma separated list of ITEM_INFO1 for ITEMs in one collection and put it in ITEMS_INFO1 field in ITEM_COLLECTION column you know. So, whenever any ITEM changes I need to somehow have a callback to the corresponding ITEM_COLLECTION entity bean to update its ITEM_INFO1 by running some query again to refresh the entry...
You can consider this ITEM_INFO1 in ITEM as short description for the ITEM and ITEMS_INFO1 in ITEM_COLLECTION as comma separated values to be shown under ITEM_COLLECTION in the display you know...
Hope I am able to explain my situation.
Regards
Maulin
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
anybody has got any ideas here?
I hope I was able to put down my problem properly.
Regards
Maulin
Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
Hi,
Have u tried writing the same code in ejbPostCreate method?
Seetesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Computed value in the entity bean