Thursday, June 16, 2011

RestEasy Avoid -LazyInitializationException

When we work with JPA one cannot avoid using relations. For eg UserAccount has relation with UserAccountProfile. We often come across LazyInitializationException.
However when accessing UserAccount resource we may need to suppress xml generation for UserAccountProfile. Solution is to use @XmlTransient

      * @return the useraccount
     public Useraccount getUseraccount() {
         return useraccount;

I have Annotated getUserAccount in the Entity This annotation does not work with fields.
Adtionally you can use @ManyToOne(fetch = FetchType.LAZY) to avoid the database call :)

Applies to : Jboss,JAX-WS,RestEasy,JPA,Hibernate

No comments: