Hi,
After upgrading to Hibernate 3.2.0 CR4 and HEM 3.2.0 CR2 from the previous version available in ejb3 RC8 I get the following exception
Quote:
javax.persistence.PersistenceException: org.hibernate.HibernateException: instance not of expected entity type: test.Figure$$EnhancerByCGLIB$$dd8f48aa is not a: test.Figure
when getting an object from the query and casting it to the correct instance i.e.
Code:
Query query = em.createNamedQuery("findFigures");
query.setParameter("radius", new Integer(20));
query.setMaxResults(1);
return (Circle) query.getSingleResult();
with the following two simple classes
Code:
package test;
import javax.persistence.*;
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Figure {
@Id
protected Long id;
@ManyToOne(fetch = FetchType.LAZY)
protected Figure parent;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Figure getParent() {
return parent;
}
public void setParent(Figure parent) {
this.parent = parent;
}
}
Code:
package test;
import javax.persistence.Entity;
@javax.persistence.NamedQueries({
@javax.persistence.NamedQuery(name = "findFigures",query = "select a from Circle a where a.radius=:radius")
})
@Entity
public class Circle extends Figure {
public Circle(){};
public Circle(Integer r){
radius = r;
}
protected Integer radius;
public Integer getRadius() {
return radius;
}
public void setRadius(Integer radius) {
this.radius = radius;
}
}
The stacktrace is :
Quote:
javax.persistence.PersistenceException: org.hibernate.HibernateException: instance not of expected entity type: test.Figure$$EnhancerByCGLIB$$dd8f48aa is not a: test.Figure
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:641)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:99)
at test.SampleFigureBean.findFigures(SampleFigureBean.java:32)
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:589)
...
Caused by: org.hibernate.HibernateException: instance not of expected entity type: test.Figure$$EnhancerByCGLIB$$dd8f48aa is not a: test.Figure
at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassEntityPersister(AbstractEntityPersister.java:3568)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1347)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:180)
at org.hibernate.engine.CascadingAction$9.noCascade(CascadingAction.java:347)
at org.hibernate.engine.Cascade.cascade(Cascade.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:130)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:121)
at org.hibernate.event.def.AbstractFlushing|#]
[#|2006-09-22T16:15:37.623+0300|WARNING|sun-appserver-pe9.0|javax.enterprise.system.stream.err|_ThreadID=11;_ThreadName=p: thread-pool-1; w: 2;_RequestID=3a8cd8f6-247a-49dc-9b00-e620
12db0194;|EventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:80)
... 81 more
In the database there are 2 instances of Circles and the one with the id=20 (that is retrieved by the query) has as the parent the other instance.
My understanding is that the proxy created by cglib should be a subclass of Figure. In the ejb3 RC8 the same code works fine. Any ideea what is wrong?
Btw I am using Hibernate in glassfish but I do not think that should matter.