-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: "detached entity passed to persist" On Single Tabl
PostPosted: Mon Jul 28, 2008 1:29 am 
Newbie

Joined: Fri Jul 25, 2008 5:22 am
Posts: 12
I'm using Seam 2.02, Hibernate 3.2.4.sp1, Tomcat 6, MySQL 5, and I have the following SQL/DDL table in my MySQL database:

Code:
CREATE TABLE foo.member (
  member_id INT(10) AUTO_INCREMENT NOT NULL,
  lastname VARCHAR(20) NOT NULL,
  firstname VARCHAR(20) NOT NULL,
  onlinename VARCHAR(20) NOT NULL,
  password VARCHAR(15) NOT NULL,
  url VARCHAR(50) NULL,
  membersince DATE NOT NULL,
  email VARCHAR(40) NOT NULL,
  status VARCHAR(10) NOT NULL,
  PRIMARY KEY (member_id)
);


The Java class equivalent (using annotations) is:

Code:
@Entity
@Name("member")
@Table(name="Member")
public class Member implements Serializable {

    private static final long serialVersionUID = 1881413500711441951L;
    private Integer memberID;
    private String lastName = "";
    private String firstName = "";
    private String onlineName = "";
    private String password = "";
    private String emailAddress = "";
    private String url = "";
    private Date memberSince = new Date();
    private String status = "";

...

@Id @GeneratedValue
@Column(name = "member_id")
public Integer getMemberID() {
      return memberID;
}

public void setMemberID(Integer memberID) {
      this.memberID = memberID;
}
}



I have a long running conversation that takes place between three different web pages. The first page where the conversation starts has a method that does the following:

Code:
  newMember = new Member();
  newMember.setMemberID(tempKey++);


The last method does this (when it is called):

Code:
em.persist(newMember); // this blows up


Which causes the error message:

Code:
org.hibernate.PersistentObjectException:
  detached entity passed to persist


I'm not sure even what the error message means and I'm not sure how to solve it. I've tried the following:
- Not using @GeneratedValue, using @GeneratedValue with AUTO and IDENTITY for a strategy
- newMember = em.merge(newMember); // which doesn't work either because the DB has nothing in it
- persisting the Member object in the first method call right after instantiating it but same error
- member ID as an int, Integer, Long, and long
- Not initializing the ID value when it's a reference type (i.e., Long or Integer) but this gives me NPEs

I haven't tried voodoo or waving a dead chicken over it but that's about the only other thing that comes to my mind. Anyone know what I might be doing wrong here?

Any help most appreciated.

_________________
“The Edge... there is no honest way to explain it because the only people who really know where it is are the ones who have gone over.” - Hunter S. Thompson


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.