users@glassfish.java.net

catching JPA NonUniqueResultException

From: <glassfish_at_javadesktop.org>
Date: Fri, 09 Feb 2007 03:17:49 PST

hi,


I have a method in an EJB that calls entityManager.createNamedQuery("query").getSingleReslt();


EM.getSingleResult() throws 'NonUniqueResultException' unchecked exception if more than one result were returned,

I declared my EJB method as:

public void loadEntities() throws NonUniqueResultException;



but when the exception occures, an 'javax.ejb.TransactionRolledbackLocalException' exception is thrown and not the NonUnique one.


Is there any way to keep the exception unchecked but still threw so I can catch and handle it in other places?


I currently made a workaround that catch the 'NonUniqueResultException' in my EJB method and I throw another exception that I wrote by myself. but I prefer to handle javax.persistance exceptions and not wrap them all the time.


thanks!
[Message sent by forum member 'demiant' (demiant)]

http://forums.java.net/jive/thread.jspa?messageID=202844