-->
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.  [ 7 posts ] 
Author Message
 Post subject: UserType Versus CompositeUserType
PostPosted: Wed Aug 31, 2005 10:45 am 
Beginner
Beginner

Joined: Wed Dec 17, 2003 10:13 am
Posts: 33
It's not clear to me from the javadocs what the difference is between UserType and CompositeUserType. Can someone explain?

I'm writing a MoneyType, similar to what's in Chapter 6 of "Hibernate In Action". The difference is that I want to have two attributes: an amount and a currency that's variable. (The example only has an amount and assumes USD.)

I'm almost finished with it. It's straightforward, except for the disassemble, assemble, and replace methods. (Gotta figure those out, too.) Then I came across CompositeUserType. It brought me up short. Was I implementing the wrong interface?

%

_________________
MOD


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 10:48 am 
Beginner
Beginner

Joined: Wed Dec 17, 2003 10:13 am
Posts: 33
Now I've also found CustomType in the Hibernate 3.0 javadocs. Is that preferred? What is the accepted idiom for Hibernate 3.0?

%

_________________
MOD


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 10:52 am 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
As far as I know, a CompositeUserType is an extended UserType, for complex situations. With CompositeUserType, you can define properties in your type, while UserType would only be interfaced do define simples types.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 10:58 am 
Beginner
Beginner

Joined: Wed Dec 17, 2003 10:13 am
Posts: 33
Geez, I wasted a credit for nothing. 8(

I should have read a bit further in "Hibernate In Action". They implement UserType for the sake of a legacy database, then follow that with an example that extends CompositeUserType for a new database.

Not sure how CustomType fits into this mix.

%

_________________
MOD


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 11:37 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
Typically, you use UserType to map an application class that can be identified(or rebuilt) based on a single colum in a table. As an example, prior to JDK1.5, you may use some kind of home grown or 3rd party enum types, then you can save them as plain integers in tables. I use CompositeUserType when I need to use more than 1 columns in database to represent an object.

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 11:44 am 
Beginner
Beginner

Joined: Wed Dec 17, 2003 10:13 am
Posts: 33
Excellent, thank you, Jason.

And now one more thing: org.hibernate.type.CustomType? Is that preferred over the other two now for Hibernate 3.0? The javadocs don't say how long this interface has been part of the API, and I don't have 2.x javadocs anymore.

%

_________________
MOD


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 11:47 am 
Beginner
Beginner

Joined: Wed Dec 17, 2003 10:13 am
Posts: 33
I guess this new credit system is a good way to encourage folks to be more active on the Hibernate Forum. The Java Forum has the Dukes method, which allows you to accumulate Dukes for sound advice at the discretion of the questioner. But you can start as many new threads as you wish and never spend any Dukes.

Your system makes it inconvenient to start a lot of threads. Looking at the quality of questions on the Java Forum, that might be a good thing.

I'm going to have to become more active so I can continue to tap into the talent here. Thanks to all who advise. Sincerely, %

_________________
MOD


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