-->
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: howto generate a primary key only if none is assigned?
PostPosted: Wed Sep 16, 2009 9:26 am 
Newbie

Joined: Wed Sep 16, 2009 8:51 am
Posts: 1
Is it somehow possible to tell Hibernate to override the primary key generated by a sequence on some condition?

For example i have an entity with this primary key - int:

@GeneratedValue(strategy = GenerationType.SEQUENCE,generator="pk_seq")
private Integer id;

normally im perfectly happy with this, so I can create objects and call:

session.save(Object);

and hibernate creates the primary key.
but now i want to program a tool to import database entrys from csv-files, where the primary key that should be used is already specified:

id;day;month;year;time;historical;quality;att1;v1;att2;v2
1;12;09;2009;16:04:48;;;1;+26.3;2;34.27

so i create my objects:

Object o = new Object();
o.setId(1);
...
but when i call
session.save(o);
hibernate uses the generated key instead of the one assigned.
can i tell hibernate to generate a primary key only if none is assigned?


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.