3 Replies Latest reply on Jan 28, 2009 10:43 PM by Paul Keogh

    Help needed with JPA please...

    Paul Keogh Novice

      I have written a test that writes a record to the database twice. Everything is the same except for one element of the entity ID which I have defined as;

          @GeneratedValue(strategy=GenerationType.TABLE, generator="CDR_GEN")
          @Column(name="id", nullable=false)
          public long getId() {
              return this.id;
          public void setId(long id) {
              this.id = id;

      I thought this is enough to uniquely construct the entity ID but I get;

      org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

      When there is only one record, the ID is generated and makes it to the database just fine.

      So, clearly the generated ID is not making it into the session - googling suggests I can wrap a TX around every DB write or call flush() but I was wondering if theres an alternative ? Or am I way off in this approach ?