I forgot to include what is the problem in the first place.
If you try to insert an entity that has the @Id field set, a value for that field will still be generated and the value that was there will be ignored.
Let's look at the following scenario:
I have a user defined like this :
id = 1
username = joe
This user is deleted. It is later found that this user has to be restored. How do we go about restoring him with the same PK.
If I create an instance of user on which I set id = 1 and username = joe, Hibernate will generate a new id when the entity is persisted ignoring the one that I set. Here is how the id field is annotated:
Code:
@Id
@GeneratedValue( generator = "ids" )
@Column( name = "ID", unique = true, nullable = false)
public Long getId() {
return this.id;
}
public void setId( Long id ) {
this.id = id;
}
I'd like hibernate not to generate an Id when it is already set.
Hope this clarifies it...