users@glassfish.java.net

Re: Check scope of entity - managed or unmanaged ?

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Fri, 25 Jul 2008 13:37:46 -0700

Hi Danny,

Entity itself doesn't know if it's managed or not (unless you tell it about an
EM that it can call). You can do something like try to access a lazy field, and
catch the exception inside your toString method, then decide what to add to the
result.

HTH,
-marina

glassfish_at_javadesktop.org wrote:
> Hi,
>
> i would like to create a toString entity method returning some fields from the
> entity bean. inside the container, all works fine, but if i return the entity to the client,
> outside the container (entity unmanaged), i got an org.hibernate.LazyInitializationException
> exception, because the field is lot "touched" inside the container - this is ok.
>
> Can i check in the Entity.toString method, if the entity is managed (inside container) or
> unmanaged (outside container) to avoid this LAZY-exception ?
>
> regards
> Danny
> [Message sent by forum member 'danny70437' (danny70437)]
>
> http://forums.java.net/jive/thread.jspa?messageID=289022
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>