-->
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.  [ 4 posts ] 
Author Message
 Post subject: Register class to map a Custom Value Type
PostPosted: Fri Feb 20, 2004 4:58 pm 
Newbie

Joined: Fri Feb 20, 2004 3:22 pm
Posts: 2
I currently have a MonetaryAmount object to represent an amount and currency value. To have Hibernate persist this would be easiest with a CompositeUserType, but I don't like creating a dependency in my MonetaryAmount class on hibernate. Is there a way to create a seperate class to do the mapping and then somehow register this mapping class to handle all MonetaryAmount objects?

Would anyone else find this useful?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 5:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Maybe I'm missing something here, but it seems like your missing the point of a UserType. The UserType implementation acts as this buffer between the actual type you want mapped in hibernate.

Basically, you'd have a MonetaryAmount class (the existing class) and MonetaryAmountUserType (or whatever you want to call it. Then you'd map the MonetaryAmount in the hibernate mapping using type="MonetaryAmountUserType". This exists this way exactly for the purpose you mention: avoiding dependencies on hibernate in your business classes.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 8:45 pm 
Newbie

Joined: Fri Feb 20, 2004 3:22 pm
Posts: 2
Yep, I completely missed the point. I thought that my type had to implement the hibernate interface for the mapping to take place. Specifying the type works great.

One other novice question: if I specify that the type is immutable (isMutable() returns false), do I need to implement the setPropertyValues() method of the CompositeUserType interface?

thanks
scott


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 8:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Yes. isMutable() just means that the property objects internals can not change, not that the property itself can not change (java.util.Date would be mutable for example, a String would not be). This for allowing hibernate to take a shortcut when dirty checking.


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