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;
}
}