1 Reply Latest reply on Jul 16, 2005 12:28 PM by Emmanuel Bernard

    EntityManager.contains() problems

    Joachim Van der Auwera Expert

      Trying to check whether an entity is attached to the persistent context fails for lazy loaded entities.

      It gives an error like Object$$EnhancedByCGLib is not a persistent entity.

      I haved worked around this with the following code :

       protected void init( EntityManager em )
       {
       this.em = em;
       if ( em instanceof InjectedEntityManager )
       {
       InjectedEntityManager iem = (InjectedEntityManager) em;
       org.hibernate.Session session = iem.getHibernateSession();
       if ( !session.contains( entity) )
       {
       entity = em.find( DMCarBean.class, entity.getUOID() );
       }
       }
       else
       {
       if ( !em.contains( entity ) )
       {
       entity = em.find( DMCarBean.class, entity.getUOID() );
       }
       }
       }