-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Primary Key Problem: Setting id manually and by sequence
PostPosted: Fri Jul 15, 2011 5:17 am 
Newbie

Joined: Fri Jul 15, 2011 5:01 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.