-->
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.  [ 8 posts ] 
Author Message
 Post subject: custom IdentifierGenerator & UserType
PostPosted: Sat Dec 13, 2003 7:04 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 2:26 pm
Posts: 56
Location: San Diego, CA
Is it possible to implement a custom IdentifierGenerator for a table that uses an identify column for pk and have that generator work with a custom UserType?

Here's my current setup for a table:

<id name="id" column="message_log_id" type="edu.ucsd.som.hibernate.NumericString">
<generator class="native"/>
</id>

NumericString type is designed to simply convert a number into a string (e.g. 123456 becomes "123456")


Currently, if using "native" generator, I get "net.sf.hibernate.id.IdentifierGenerationException: this id generator generates long, integer, short." So, it looks like I need to write a custom generator. Any pointers on how to do it? I've read the docs and saw the example at http://hibernate.bluemars.net/50.html, but I'm still lost.


Thanks
Dmitry


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 1:33 am 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
I wonder why your primary key needs to be anything more than a primative. If you really can't use a primative or simple type could you just add a get/set method that takes whatever your database returns and use that to construct a edu.ucsd.som.hibernate.NumericString?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 4:02 am 
Regular
Regular

Joined: Wed Sep 10, 2003 2:26 pm
Posts: 56
Location: San Diego, CA
i have tables with two kinds of pk: auto_increment and string. I wanted to streamline the persistent object interface by abstracting the PK's type. Implementing this abstraction at Hibernate's layer seemed like a logical thing to do. I didn't think it would be so difficult (impossible?).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 8:23 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Have a look at Hibernate srcs net/sf/hibernate/id
Those implementations are quite simple.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 11:40 am 
Regular
Regular

Joined: Wed Sep 10, 2003 2:26 pm
Posts: 56
Location: San Diego, CA
I've already looked at the sources also. No help there. I tried returning, just like the IdentityGenerator, a null (earlier versions) or an empty string (later versions). Neither worked for me.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 8:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It is not possibly to use identity columns with a custom identifier type.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 9:10 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 2:26 pm
Posts: 56
Location: San Diego, CA
thanks, gavin. i wish i could find this out earlier (http://forum.hibernate.org/viewtopic.php?t=350) :D


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 9:18 am 
Newbie

Joined: Tue Sep 02, 2003 10:35 pm
Posts: 9
gavin wrote:
It is not possibly to use identity columns with a custom identifier type.


This is not strictly true. I submitted a patch (HB-92) in may last year that supports using a custom identifier type with native generated identifiers but it has not yet been accepted/integrated.

Chris


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.