I have a class which has attribute of datatype joda.money. How can I map this attribute into mysql.
my class is:
@Table(name="products") public class Product(){ @Column(name="name") String name; @Column(name="money") Money money; }
I am using spring hibernate
Can anyone tell how to store this model into mysql?
You have more choices here.
Money
.BigDecimal
for amount andString
for currency. Then create transient synthetic fieldMoney
and create it in getter (see example below).UserType
and provide serialization/deserialization by your own. See javadoc UserType and documenatation Custom types using org.hibernate.usertype.UserType. Take a look at this implementation ofCompositeUserType
.You can include Jadira Usertypes project which provides Joda
Money
support for Hibernate (I've never tryied anyway)