Announcement Announcement Module
Collapse
No announcement yet.
problem cglib and getResultList() Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem cglib and getResultList()

    Hi, This function is throwing and exception .....

    Code:
    public List<UnidadAdministrativa> findHijos(UnidadAdministrativa unidad) {
    		
    Query query = em.createQuery("SELECT unidad FROM    unidadAdministrativa unidad WHERE unidad.padre = :unidad");
    		
    query.setParameter("unidad",unidad);
    			
    return	query.getResultList(); <--- HERE IS THE PROBLEM WITH CGLIB -->
    
    }
    I traced the error and the problem is in query.getResultList()....

    Anyone can help me ..please.


    Code:
    	
    Caused by: org.hibernate.HibernateException: instance not of expected entity type: com.dominio.unidades.Unidad$$EnhancerByCGLIB$$34d29add is not a: com.dominio.unidades.Unidad
    	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.AbstractFlushingEventListener.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.getResultList(QueryImpl.java:64)
    	... 49 more
    14:54:39,468  INFO SessionFactoryImpl:767 - closing

  • #2
    Haven't you already had this problem before and solved it? What was the previous solution?

    Comment


    • #3
      Hi , Kardl, no, i make all the interfaces that hibernate faq says but it doesn't work, i went on tracking the error and i found it where i mentioned in the previous post.
      I have tried everything but it semms not to work.
      i don't know what to try...
      I' would apreciate any help ..

      Thanks

      Comment


      • #4
        I'll have to start out by saying I'm not really sure. This is just observation. I notice that your object name is the query isn't the correct case.

        Shouldn't
        Code:
        SELECT unidad FROM unidadAdministrativa
        Actually read
        Code:
        SELECT unidad FROM UnidadAdministrativa
        Another thing. Instead of using the unidad as the parameter, try looking it up by id instead. It's just an idea.
        Code:
        Query query = em.createQuery("SELECT unidad FROM UnidadAdministrativa unidad WHERE unidad.padre = :unidad");
        query.setParameter("unidad",unidad);
        Becomes (where id is the method to retrieve the identifier)
        Code:
        Query query = em.createQuery("SELECT unidad FROM UnidadAdministrativa unidad WHERE unidad.padre.id = :unidadId");
        query.setParameter("unidadId",unidad.getId());

        Comment


        • #5
          proxy problem

          Hi Karld, i tried your solution but it doesn't work. This weekend i was debugging the application and i found that the problem is with the proxies that generates hibernate. For example:
          I have the following object with data:

          a parent...

          Unidad.id = 1,
          Unidad.nombre="Facultad de derecho",
          Unidad.padre="null"

          and a child...

          Unidad.id=2
          Unidad.nombre="Secretaria administrativa"
          Unidad.padre="....$CGLIB$$Unidades.....(..a proxy that generates hibernate, to use lazy loading, to represent the unit with id=1, see up).

          When i tried to merge, or load the unit with id=2, it complaints about the proxy.

          I read in hibernate(single-ended association)
          http://www.hibernate.org/hib_docs/v3...rformance.html

          that i have to make an interface for my objects declaring the buisness method, and to program with interfaces. I did that, but couldn't declared and association with @oneToMany over an interface. So i got stuck again.
          I wonder is there a way to represent the composition pattern, using lazy association(single-ended)?? I don't want to use an eager loading for this association.

          Bye

          Comment

          Working...
          X