Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Get look up data from entity bean- EQL usage  RSS feed

 
Gaurav Gupta
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a situation where before creating an Entity via an Entity bean, I need to do some validation on the properties of this entity. This validation is done by querying a statis data table look up in the database.
If the validation is successful then I create the entity else throw a proper exception.

Now - shall I code an Entity EJB for looking up this table and then do a Select on it(by EQL) to find out the validation data, or can I somehow use a DAO for the look up table from within my parent Entity EJB?

Shud I make Entity bean on look up data which is anyways not be transaction managed? Whats the best approach?

Thanks,
Gaurav Gupta
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are my initial (but not necessarily my best) thoughts.

You could have an entity bean per table. Let's use CMT, and let's declare both beans to have the Required transaction attribute as it seems reasonable to believe that the validation and creation are atomic.

Start by doing your validation. If it fails, you deal with it as follows. If the client expects a failure (can recover), invoke setRollbackOnly() and throw an application exception. If the client does not expect a failure, then encapsulate the exception in an EJBException and throw it to the container. Either way, the container will rollback the transaction.

If the validation succeeds, then go ahead and create the entity (this will run in the existing transaction).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!