-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Usage of stored Serializable -> LazyInitializationException
PostPosted: Fri Jun 18, 2010 2:37 pm 
Newbie

Joined: Fri Jun 18, 2010 2:14 pm
Posts: 2
I have an abstract class Atom that implements Serializable. I have an other class IntegerAtom that extends Atom class.

Storing it works perfectly, and also retrieve it works fine. But when I call the getType() for the Data object I get the below exception. I thought that putting the lazy=false on the object would help out, but it didn't :(

Anyone with some insight in this?

Code:
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
   at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:132)
   at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:174)
   at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
   at package.Data_$$_javassist_2.getValue(Data_$$_javassist_2.java)
   at package.DataHandlerTest.testGetAtom(DataHandlerTest.java:146)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   ...


Code:
<hibernate-mapping>
   <class name="package.Data" table="Data">
      <id name="objectID" column="DataId" type="long">
         <generator class="native"></generator>
      </id>
      <property name="type" column="Type" type="string" />
      <property name="value" column="Value" type="package.Atom"
         lazy="false" />
   </class>
</hibernate-mapping>


Code:
public class Data extends CommonDataType {
  private Atom value;
  private String type;

  public Data() {
  }

  public Data(Atom value, String type) {
    super();
    this.value = value;
    this.type = type;
  }

  public Atom getValue() {
    return this.value;
  }

  public void setValue(Atom value) {
    this.value = value;
  }

  public String getType() {
    return this.type;
  }

  public void setType(String type) {
    this.type = type;
  }
}


Code:
public abstract class Atom implements Serializable {
  private static final long serialVersionUID = -4979761388407826026L;

}


Code:
public class IntegerAtom extends Atom {
  private static final long serialVersionUID = 8817920877569521004L;
  private Integer value;

  public IntegerAtom(Integer value) {
    this.value = value;
  }

  public Integer getValue() {
    return this.value;
  }

  public void setValue(Integer value) {
    this.value = value;
  }

}


Top
 Profile  
 
 Post subject: Re: Usage of stored Serializable -> LazyInitializationException
PostPosted: Sat Jun 19, 2010 10:36 am 
Newbie

Joined: Fri Jun 18, 2010 2:14 pm
Posts: 2
This was solved by doing:

Code:
if (!Hibernate.isInitialized(object)) {
  Hibernate.initialize(object);
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.