-->
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.  [ 3 posts ] 
Author Message
 Post subject: Mapping of non auto-increment ids (newbie)
PostPosted: Thu Jun 18, 2009 6:09 am 
Newbie

Joined: Mon Jun 01, 2009 3:34 pm
Posts: 4
Hi,
I'm trying to map a class called User to a table of the same name whose primary key is an integer but is NOT auto-increment.
The examples of mapping files I have seen propose the following kind of definition:

<id name="id"column="user_id"type="long"unsaved-value="null">
<generator class="native"/>
</id>

But I suppose this only applies to auto-increment fields.
What do I need to specify instead of <generator class="native"/> for a non-autoincrement field?
Thanks very much.


Top
 Profile  
 
 Post subject: Re: Mapping of non auto-increment ids (newbie)
PostPosted: Thu Jun 18, 2009 8:05 am 
Beginner
Beginner

Joined: Fri Feb 13, 2009 5:27 am
Posts: 36
Location: India
HI jkala...

If you need to assign the identifier yourself in your application, then use the assigned generator. You set
the identifier using the set<identifier> method of the Java class. The application assumes the
responsibility of making sure the id value is unique; otherwise, you’ll probably get a database insert exception.

So....

<id name="id"column="user_id"type="long"unsaved-value="null">
<generator class="assigned"/>
</id>

bye.tc.

_________________
parag


Top
 Profile  
 
 Post subject: Re: Mapping of non auto-increment ids (newbie)
PostPosted: Thu Jun 18, 2009 9:29 am 
Newbie

Joined: Mon Jun 01, 2009 3:34 pm
Posts: 4
Thanks a lot!


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

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.