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

  • problem cglib and getResultList()

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

    public List<UnidadAdministrativa> findHijos(UnidadAdministrativa unidad) {
    Query query = em.createQuery("SELECT unidad FROM    unidadAdministrativa unidad WHERE unidad.padre = :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.

    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(
    	at org.hibernate.impl.SessionImpl.getEntityPersister(
    	at org.hibernate.engine.ForeignKeys.isTransient(
    	at org.hibernate.engine.CascadingAction$9.noCascade(
    	at org.hibernate.engine.Cascade.cascade(
    	at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(
    	at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(
    	at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(
    	at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(
    	at org.hibernate.impl.SessionImpl.autoFlushIfRequired(
    	at org.hibernate.impl.SessionImpl.list(
    	at org.hibernate.impl.QueryImpl.list(
    	at org.hibernate.ejb.QueryImpl.getResultList(
    	... 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?


    • #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 ..



      • #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.

        SELECT unidad FROM unidadAdministrativa
        Actually read
        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.
        Query query = em.createQuery("SELECT unidad FROM UnidadAdministrativa unidad WHERE unidad.padre = :unidad");
        Becomes (where id is the method to retrieve the identifier)
        Query query = em.createQuery("SELECT unidad FROM UnidadAdministrativa unidad WHERE = :unidadId");


        • #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...

 = 1,
          Unidad.nombre="Facultad de derecho",

          and a child...

          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)

          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.