Check scope of entity - managed or unmanaged ?

View: New views
3 Messages — Rating Filter:   Alert me  

Check scope of entity - managed or unmanaged ?

by glassfish-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
For additional commands, e-mail: users-help@...


Re: Check scope of entity - managed or unmanaged ?

by Marina Vatkina :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@... 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@...
> For additional commands, e-mail: users-help@...
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Check scope of entity - managed or unmanaged ?

by glassfish-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

thanks for answering - i catched the
exception as you wrote - and all works (-:

regards
Danny
[Message sent by forum member 'danny70437' (danny70437)]

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

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...

LightInTheBox - Buy quality products at wholesale price