Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ejbCreate  RSS feed

 
bobby chaurasia
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a cmp bean, ejbCreate( ) inserts a row into the database. How do we code the ejbCreate() method if all we want is to query the database and make no insertions or deletions.
How would ejbCreate( abcPK ){
}
suit in this scenario ( abcPk is the primary key ).
2) Could we have multiple ejbCreate methods ?
3) What happens if there is no ejbCreate method in the bean. ( i guess it will fail the verify ejb test )

Any clues anyone ?
Thanks

[ May 14, 2003: Message edited by: bobby chaurasia ]
 
Dave Cronin
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The EJB spec, 10.6.4 says "The entity bean class may define zero or more ejbCreate<METHOD>(...) methods"
It is quite possible to have read only entity beans that read existing data from a database. In that case there will be no ejbCreate methods.
You can have as many ejbCreate methods as you like, which is similar to having multiple constructors. The primary key would still be the same though.
I would be interested to hear of anyone actually using an entity bean without an ejbCreate method.
 
Anup Katariya
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think one should not use any sql in CMP entity beans. If required you should use BMP.
Thanks,
Anup
 
bobby chaurasia
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave,
I tend to agree with you. This was my gut feel as well but I just wanted to have a second opinion. Yes I would also like to hear from someone who has used beans without the create method.
Cheers
 
Dave Cronin
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thinking of a possible scenario, you could have a situation where you import data from another application which have already defined primary keys for the entities. Then you could probably use CMP entity beans just to query the database. I am not so sure about how to prevent deletions - maybe you could throw an exception if any tries to call remove().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!