Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to persist entity with@GeneratedValue PK but set id(PK) programatically

843830Feb 26 2010 — edited Mar 1 2010
Hi
I have an entity with
@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    public long getId() {
	return id;
    }
I have application that is replicated on 2 servers each working with 2 equal data bases. I persist entity on server1 and after that send the entity via jms to server2 which must persist the same entity too. But it throws me exception
javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: MyEntity
because the entity have set PK id and the persistence menager thinks it is already persisted. How can i have AUTO generated value and the same time to set PK id when i need?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 29 2010
Added on Feb 26 2010
3 comments
421 views