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: Override @GeneratedValue at insert
PostPosted: Wed Apr 15, 2009 5:21 am 
Newbie

Joined: Wed Apr 15, 2009 5:06 am
Posts: 1
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


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.