-->
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: Custom type for auto-generated id column
PostPosted: Tue Dec 09, 2008 11:13 pm 
Newbie

Joined: Tue Dec 09, 2008 11:02 pm
Posts: 2
Hi,

I'd like to use a custom type for an id field, that's represented as an INTEGER in the database.

I can't seem to get Hibernate to cope with this, as it's expecting either an Integer, Long, String, etc. in the case of auto-generated id assignment.

Is there a way I can do this without having to write a setID(Integer id) { this.id = new MyIDClass(id); }
method?

My custom type is basically just a wrapper around an Integer, and it has the appropriate custom type defined and used for Hibernate.
It extends org.hibernate.type.IntegerType, but if I override the public Class getReturnedClass() method to return say MyIDClass.class, it throws the error that says it was expecting an integer, long, string, etc....
But if I return Integer.class from that method, it goes fine until it expects a setter like setID(Integer id).
So is there a way to tell Hibernate to work with custom id types for auto-generated values, and can someone explain how?

Thanks,
David


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2008 4:20 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I guess you have to implement your own id generator since the built-in generators in Hibernate only support the types that you mention.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2008 7:24 am 
Newbie

Joined: Tue Dec 09, 2008 11:02 pm
Posts: 2
Yeah well I've been browsing through the source and submitted something sort of a bug report / feature enhancement request because custom types for auto-generated ids could be implemented -- in my belief -- in about 10 lines of added code. Creating a custom id generator just for this seems overhead, when it could be accomplished with just a few lines elsewhere.

But if someone knows of something that I'm missing here, please let me know.


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.