• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

DuplicateKeyException

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DuplicateKeyException IS-A CreateException.
 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
That new kid is a freak. Show him this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic