users@glassfish.java.net

Re: catching JPA NonUniqueResultException

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Mon, 12 Feb 2007 12:21:17 -0800

Hi,

Yes, 'NonUniqueResultException' is an unchecked exception according to the spec,
so your solution for catching it inside a remote method (is it?) is to have a
try-catch block inside that method and handle it according to your internal logic.

Regards,
-marina

glassfish_at_javadesktop.org wrote:
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>