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: Customize id-sequence
PostPosted: Thu Jan 04, 2007 4:59 am 
Newbie

Joined: Thu Jan 04, 2007 4:40 am
Posts: 9
Hi,

Hibernate version: 3.2

Name and version of the database you are using: Postgres 8.1.4

reading doc I'm quite confused. I'm newbie to hibernate and I don't know exactly if and how is it possible customize id-sequence in a table. My own case is:

my id-sequence: 1byte-7bytes and so for example:
1-0...1
1-0...2
....
2-0...1
etc

this id-sequence must be safe-thread.

Is it possible customize a id-sequence with hibernate? is there doc about it?

Thanks,
rand


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 5:30 am 
Beginner
Beginner

Joined: Fri Nov 28, 2003 6:57 am
Posts: 20
Hibernate enables you to write an own key generator and use it. Check out http://www.hibernate.org/hib_docs/v3/api/org/hibernate/id/IdentifierGenerator.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 9:43 am 
Newbie

Joined: Thu Jan 04, 2007 4:40 am
Posts: 9
Ok, thanks.

I suppose I need to a kind of this:

public class MyGenerator implements IdentifierGenerator {

private IdentifierGenerator myid = ...;

public Serializable generate(SessionImplementor session, Object object)
throws HibernateException {

.....
return new Bytes( ( new Long(myid).toString()).getBytes() );
}

}

<id name="id" type="long" unsaved-value="null">
<generator class="MyGenerator"/>
</id>

Is it correct?
Is it automatically safe-thread????

Thanks,
Rand


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.