Hello,
I am using a sequence to generate primary keys.
Code:
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "serial_room_id")
@SequenceGenerator(name = "serial_room_id", sequenceName = "serial_room_id", allocationSize = 1)
private Long id;
For migration purpose I need to set the primary key manually but not in normal mode.
I get an exception when I try this:
Code:
Room room = new Room();
room.setId(4711);
...
roomDAO.saveModel(room);
Exception:
javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: org.fhws.lantel.model.Room
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1153)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:678)
Is it possible to use both approaches coexistently? How?
Thanks in advance,
Ron