"Detached entity passed to persist"

"Christopher Dodunski" <[email protected]>
Newsgroups gmane.comp.java.tapestry.user
Message-ID <[email protected]>
Hi team,

I suspect you'll be able to answer this right off the top of your head, as
this error occurs in response to what I imagine is a very routine code
assignment: set a newly created user's company to be the same company as
that of the user doing the creating.


Code snippet from 'pages/user/CreateUser.java'...

    User user = new User(firstName, lastName, userName, email,
authenticator.encryptPassword(password));

    //Set the new user's company to the same as the creator's company
    user.setCompany(authenticator.getLoggedUser().getCompany());

    crudServiceDAO.create(user);


The User>>Company relationship, as defined in the User entity class...

    @ManyToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="COMPANY_ID")
    private Company company;


The Company>>User relationship, as defined in the Company entity class...

    @OneToMany(mappedBy="company", cascade=CascadeType.ALL)
    private Collection<User> users = new ArrayList<User>();


The USER table has a COMPANY_ID field, so I'd be expecting Hibernate to
create a new user with the same company ID as the user I have logged in
as.  Instead, Tapestry gives the following error...

    org.apache.tapestry5.runtime.ComponentEventException

    detached entity passed to persist: com.example.harbour.entities.Company


Why is this?  Appreciate your help.

Thanks,

Chris.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.