2 Replies Latest reply on Dec 7, 2006 7:03 PM by André Luis Leal Cardoso Junior

    "detached entity passed to persist" problem

    André Luis Leal Cardoso Junior Newbie

      Hi all,

      I'm new to seam, and I'm creating a project here

      I'm getting this Exception:

      Exception during INVOKE_APPLICATION(5): javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: br.com.dehproject.UsuarioEntity


      I know that I could use em.merge() to skip this, but I want to create a new object, not to update the actual one. My UsuarioEntity has a SESSION Scope, so that's why I get this... but I need the SESSION scope to the next page in my JSF to manage the contents of the object...

      I have a page that register the users, and then redirect to another page where I manage the contents of the user using a Entity with a EVENT scope... But if I get back to the register page, I cannot persist another one and throw the Exception that I pasted above... =/ I want to create a new object to persist that has nothing to do with the other one...

      How can I turn back and persist another object? but I also need to continue with a SESSION Scope, or I wish to have some idea from you...

      Thanks!


        • 1. Re:
          Pete Muir Master

          You will have to post some of your code at least. It also sounds like you are confused about the interaction of Seam and Hibernate.

          • 2. Re:
            André Luis Leal Cardoso Junior Newbie

            I'll try to explaim better !

            MyEntity:

            
            @Entity
            @Scope(SESSION)
            @Name(users)
            public class UserEntity implements Serializable {
            
             //variable and setters and getters
            
            }
            
            


            My Action Register:

            
            @Stateless
            @Scope(EVENT)
            @Name("register")
            public class RegisterAction implements Register {
            
             @In
             UserEntity userentity;
            
             @PersistenceContext
             EntityManager em;
            
             public String register(){
            
             //some if's and here
             em.persist(userentity);
            
             return "/anotherpage.seam";
             }
            }
            


            and in my jsf page
            <h:commandButton value="Register" action="#{register.register}" />
            



            So, I persist one Object, and It is Ok, but if I turn back and go to persist another one, I get that Exception above... I know that's because my UserEntity hava SESSION scope...

            Do I have to change the UserEntity Scope to Event? and modify somethings to make it work properly?