-->
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: Regression in Hibernate 3.2 CR4 and HEM CR2
PostPosted: Fri Sep 22, 2006 10:25 am 
Newbie

Joined: Fri Sep 22, 2006 9:27 am
Posts: 1
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 3:55 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I fixed that one aready in SVN, check Hibernate core branch 3_2

_________________
Emmanuel


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.