-->
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.  [ 2 posts ] 
Author Message
 Post subject: mapping immutable class in hibernate??
PostPosted: Mon Jul 24, 2006 7:09 am 
Beginner
Beginner

Joined: Tue Apr 25, 2006 10:46 am
Posts: 28
Hi

MonetaryAmount class from HiA book is immutable but when I try to code it using xDoclet and Spring's HibernateTemplate class, I run into a series of problems, in the end, to make it work I have to turn it into a mutable class with setter fields
for Currency and BigDecimal properties.

E.g.

Mapping for Item class with component mapping to MonetaryAmount as
reservePrice


Code:
<hibernate-mapping>

    <class
            name="org.ecomfuse.model.Item"
            table="item"

        <component name="reservePrice">

           <property name="currency">
            <column
               name="reserve_price_currency"
               not-null="true"/>
           </property>
       
        </component>
       
     .......
     
     </class>
     
</hibernate-mapping>     


Now my question is, is it possible to map an immutable class
with empty setter methods in hibernate using component tag?

If not possible, what's the practice you ppl use to map immutable class? (implementing UserType I guess..)


Thanks,

Sam


Top
 Profile  
 
 Post subject: reply
PostPosted: Mon Jul 24, 2006 8:29 am 
Beginner
Beginner

Joined: Tue Apr 25, 2006 10:46 am
Posts: 28
Problem solved.

Just have to use MonetaryAmountCompositeUserType
from HiA sample code to map immutable type with
empty setter methods for fields.

Using components tag in mapping simply won't work
because of empty setter unless you change MonetarAmount
to mutable class, defeats purpose of immutable fields

Lesson: use CompositeUserType to map immutable types

Mapping used in xDoclet:

Code:
/**
    * @hibernate.property type="org.ecomfuse.dao.hibernate.customtypes.MonetaryAmountCompositeUserType"
    * @hibernate.column name="initial_price" not-null="true"
    * @hibernate.column name="initial_price_currency" not-null="true"
    */
   public MonetaryAmount getInitialPrice() {
      return initialPrice;
   }


Regards,

Sam


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