1 Reply Latest reply on Dec 19, 2013 8:00 AM by suikast42

    Jboss 7.2.0.Final BUG in CDI Container ?

    suikast42

      Hi,

       

      I spent my last three days to understand why hibernate throw

      javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.siemag.jpatest.backend.model.User
      

       

      At first I thought I have a problem with my biderctional many-to-many relationship and play with that. The strange thing for me was that the test work two or three times then it crashes.

       

      After deep debugging I find out that I get an detached object from my DAO ( EJB stateless).  This was Injected with @Inject. And that was the problem. If I change it to @EJB everything works as expected.

       

      Injection happens here

      See UserDAOHibernateTest:50
      

      Expetion is thrown here:

      See UserDAOHibernateTest:315
      

       

       

       

      I read about that I can inject EJB beans with @Inject. And I did that in my test.

      Is there a bug in Weld ?

      Or if I use @Inject instead of @EJB must the dao inject other EJB with @Inject too ??

       

      You can find the testapp at github.

        • 1. Re: Jboss 7.2.0.Final BUG in CDI Container ?
          suikast42

          For clarification:

          UserDAOHibernateTest.java
          
          
          // If I use @Inject for userDAO then it can be happen that the user1 is detached ( this call is surrounded with a transaction)
          
          line 315: User user1 = userDAO.getByName(userName1);
          

           

           

          GenericHibernateDAO.java
          
          line 52:    public T getByName(String name) {
                  return (T) eDAO.getByName(getPersistentClass(), name);
              }
          

           

           

          So if I use @Inject in my test then it can be happen that the result user1 and the result of getByName are different references:


          For example:

          eDAO returns user@FFFFF but user1 is user@AAAAA