This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Computed value in the entity bean

 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anybody has got any ideas here?
I hope I was able to put down my problem properly.
Regards
Maulin
 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Have u tried writing the same code in ejbPostCreate method?
Seetesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic