File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes JPA-Hibernate - EntityExistsException Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA-Hibernate - EntityExistsException Question" Watch "JPA-Hibernate - EntityExistsException Question" New topic
Author

JPA-Hibernate - EntityExistsException Question

prasanna kumar
Greenhorn

Joined: Jun 27, 2004
Posts: 12
We recently converted our EJB2.1 application to EJB3 (Jboss 4.2.CP07) and landed in to a problem with EntityExistsException Vs DuplicateKeyException (EJB2).
Earlier with EJB2 we were able to do operation like

try{
<EntityHome>.create(<some object>);
} catch (DuplicateKeyException ex) {
Do some other task ..involving database
}

When we converted to EJB3 ..the code looks like below

try{
em.persist(<some PO>);
} catch (EntityExistsException ex) {
Do some other task ..using em

}

In second case we learnt that we couldn't do any more operations on the em as the transaction is closed, is this the expected behavior?
If yes can anyone please suggest a different way to handle these scenarios ?
Mahesh Panchananam
Greenhorn

Joined: Jun 30, 2011
Posts: 18
It's not whether the session is closed or opened, It's JPAs way to handle duplicates.
This exception is thrown when you try to persist a duplicate entity.

try {
entityManager.create(Obj) ;
}
catch(EEE e) {
}


Rgds
Mahesh PS
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPA-Hibernate - EntityExistsException Question
 
Similar Threads
JPA-Hibernate - EntityExistsException Question
Hibernate JPA persist() not throwing EntityExistsException
EntityExistsException how to know which key i duplicate?
EntityExistsException
A EJB3 vs EJB2 question