-->
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.  [ 6 posts ] 
Author Message
 Post subject: Best way to store money using hibernate?
PostPosted: Tue Aug 24, 2004 8:08 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
What's the best way to store money in the database? I have a Money object that stores the value as a long and also contains java's Currency class. I'd like to store the combination into the database. Any place where I can find information on how to do this efficiently?


Top
 Profile  
 
 Post subject: Re: Best way to store money using hibernate?
PostPosted: Wed Aug 25, 2004 2:10 am 
Regular
Regular

Joined: Thu Aug 05, 2004 2:27 am
Posts: 54
Location: South Africa
egervari wrote:
What's the best way to store money in the database? I have a Money object that stores the value as a long and also contains java's Currency class. I'd like to store the combination into the database. Any place where I can find information on how to do this efficiently?


just create the Money.hbm.xml file, I'm not sure you need the currency class as a property though.
btw long isn't suitable unless it represents cents and you divide by 100 for $ or whatever


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 3:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Nah, I wouldn't store it as a separate entity. If it were me, I'd use a UserType. Alternatively, you could use a <component> mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 8:54 am 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
gavin wrote:
Nah, I wouldn't store it as a separate entity. If it were me, I'd use a UserType. Alternatively, you could use a <component> mapping.


That sounds reasonable. I'll look at UserTypes in the documentation to learn more about that. Thanks Gavin.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 8:55 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
There is a MonetarAmountUserType in CaveatEmptor.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 1:43 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
christian wrote:
There is a MonetarAmountUserType in CaveatEmptor.


Yep, I found that and based it. It's working just great. Thanks.


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