• Post Reply Bookmark Topic Watch Topic
  • New Topic

ejbCreate Exception question - transactions

 
michael key
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 Entity EJBs participating in an relationship. Order - Address. I'm creating the Address in the the ejbPostCreate of Order.
When I encountered a duplicate key for Order in Order's ejbCreate, I was not expecting the Address to be created, I thought a rollback would occur since i marked all my method transaction as 'required' in the descripter. It looks like the container called ejbPostCreate even though ejbCreate threw an exception. This this the way the container normally behaves, how can I solve this problem.
What do I need to do to ensure a rollback occurs.
thanks in advance!
 
Ken Loh
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm encountering this same old problem right now. Although there is a system exception (CreationException) thrown in the ejbPostCreate, the record was still created in the database. The expected rollback just doesn't kick in.

Any help would be very much appreciated.

Originally posted by michael ke:
I have 2 Entity EJBs participating in an relationship. Order - Address. I'm creating the Address in the the ejbPostCreate of Order.

When I encountered a duplicate key for Order in Order's ejbCreate, I was not expecting the Address to be created, I thought a rollback would occur since i marked all my method transaction as 'required' in the descripter. It looks like the container called ejbPostCreate even though ejbCreate threw an exception. This this the way the container normally behaves, how can I solve this problem.

What do I need to do to ensure a rollback occurs.

thanks in advance!
 
Ken Loh
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it solved. Must throw a system exception, e.g. RuntimeException. So, for my case, I throws a new EJBException which is a subclass of RuntimeException.
 
Robert Strong
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Ken,

I'm wondering how you create dependent address EntityBean in ejbPostCreate() of Order EntityBean? I thought you need to pass reference of current Order EntityBean in ejbCreate() to create related address EntityBean. Could you show me your source code?
 
Ken Loh
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To map my design to yours just map:
  • UserEntity <-> Order
  • UserProfile <-> Address




  • DBFieldException is a subclass which I extend from RuntimeException.

    At ejbPostCreate(), the primary key, userid is ready. Therefore I can use getUserId() as the parameter to create my component object.

    Originally posted by Robert Strong:
    hi Ken,

    I'm wondering how you create dependent address EntityBean in ejbPostCreate() of Order EntityBean? I thought you need to pass reference of current Order EntityBean in ejbCreate() to create related address EntityBean. Could you show me your source code?

    [ April 10, 2005: Message edited by: Ken Loh ]
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!