A class is annotated as follows and works as expected:
Code:
@Entity
public class TestEntity {
@Id
@GeneratedValue
private Long Id;
private String s;
private Integer i;
// Constructor and other setter/getter omitted...
public void setId(Long Id) {
this.Id = Id;
}
By migrating data, I would like to keep the original Id and not generate a new one (other entities references the Id):
Code:
TestEntity te = new TestEntity("insert", 5);
te.setId(PRIM_KEY);
repository.insert(te);
The set Id (PRIM_KEY) is ignored and a new Id is generated (as expected):
Hibernate:
insert
into
TestEntity
(Id, i, s)
values
(null, ?, ?)
10:08:42.825 [main] TRACE org.hibernate.type.IntegerType - binding '5' to parameter: 1
10:08:42.825 [main] TRACE org.hibernate.type.StringType - binding 'insert' to parameter: 2
Is there a way to configure/override the generation of the Id without implementing another entity?
Thx,
Anders