Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DuplicateKeyException

 
Ramakrishnan Ponmudi
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i call home.create("P123") ( that key is already exists ), i getting remote exception instead of duplicatekey (or create) exceptions. what is the reason.

similarly when will i get create, remove or finder exceptions, who is responsible for throwing it, bean provider or container.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DuplicateKeyException IS-A CreateException.
 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ramakrishnan Thanjavur:
when i call home.create("P123") ( that key is already exists ), i getting remote exception instead of duplicatekey (or create) exceptions. what is the reason.

similarly when will i get create, remove or finder exceptions, who is responsible for throwing it, bean provider or container.


These are all application exceptions, so they are bean providers responsibility.

DuplicatekeyException are supposed to be passed to the client directly instead of being wrapped as RemoteException. So probably your code encountered some other system exception.
 
Ramakrishnan Ponmudi
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i had checked one more time (even with throw clause contains DuplicateKeyException), but client gets remote exception instead of DuplicateKeyException( or create exception).
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Examine the RemoteException and see if it encapsulates another exception.
 
Ramakrishnan Ponmudi
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes , it encapsulates DuplicateKeyEsception. but how does the clients knows it

client gets : Remote exception occurs......

javax.transaction.TransactionRolledbackException: EJB Exception: : javax.ejb.DuplicateKeyException: Bean with primary key: 'P1' already exists.
at weblogic.ejb20.manager.BaseEntityManager.executeInsertStmt(Ljava.util.List;Ljavax.transaction.Transaction;Ljava.util.Set;Z)V(BaseEntityManager.java:625)
at weblogic.ejb20.manager.BaseEntityManager.executeDBOperations(Ljava.util.List;Ljavax.transaction.Transaction;Ljava.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The client can invoke getCause to return the wrapped remote exception.

Also, it seems as if EJBException was thrown, causing the container to throw RemoteException as the client is remote. This is why RemoteException rather than DuplicateKeyException was thrown to the client.
 
Ramakrishnan Ponmudi
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for reply, what can i do for getting DuplicateKeyException?
 
Ramakrishnan Ponmudi
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RemoteException occurs......
when calling getCause() on remote exception it shows:

weblogic.utils.NestedRuntimeException: Error writing from beforeCompletion - with nested exception:
[javax.ejb.DuplicateKeyException: Bean with primary key: 'P1' already exists.]
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I think is happening. When the insert fails, WebLogic Server throws weblogic.utils.NestedRuntimeException, which is a RuntimeException. As the client is remote, WLS complies with the EJB spec by thowing RemoteException to the client.

In any case, I think the client will always get RemoteException as the transaction is marked for rollback, which explains why TransactionRolledbackException (a subclass of RemoteException) is thrown by WLS.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic