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.  [ 5 posts ] 
Author Message
 Post subject: UserType in where clause
PostPosted: Tue Nov 15, 2005 7:02 am 
Newbie

Joined: Thu Dec 16, 2004 7:11 am
Posts: 7
Hibernate version: 3.0.5

Mapping documents:
Code:
<class
            name="com.pnetx.ecomm.domain.Product"
            table="Product"
    >
...
    <property name="price" type="com.pnetx.util.types.MoneyType">
            <column
                name="priceAmount"
                length="8"
                precision="2"
                not-null="true"
            />

            <column
                name="priceCurrency"
                length="3"
                not-null="true"
            />
    </property>


Given a Product class with:

Code:
public Money getPrice() ...


A Money class with:

Code:
public BigDecimal getAmount() ...
public Currency getCurrency() ...

and a corresponding MoneyType that implements UserType, then why does the following HQL query:

Code:
from Product p where ? = p.price.amount


give the following exception:

Code:
org.hibernate.QueryException: could not resolve property: amount of: com.pnetx.ecomm.domain.Product
?

How else can I select all products having a given price amount?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 8:11 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
i think that you have to make query like

from Product p where ? = p.price

and add parameter tyype Money, but query add currency from Money, too

for your query you can add nonupdatable properties amount and currency in mapping and do query with this properties


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 8:19 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
try implement CompositeUserType, too - this is better way


Top
 Profile  
 
 Post subject: Component?
PostPosted: Tue Nov 15, 2005 8:22 am 
Regular
Regular

Joined: Sat Nov 05, 2005 5:33 am
Posts: 70
Location: Linz, Austria
Perhaps you could try to map the two columns as a component:
Code:
<class
            name="com.pnetx.ecomm.domain.Product"
            table="Product"
    >
...
    <component name="price" class="com.pnetx.ecomm.domain.Money">
            <property
                name="amount"
                column="priceAmount"
                length="8"
                precision="2"
                not-null="true"
            />

            <property
                name="currency"
                column="priceCurrency"
                length="3"
                not-null="true"
            />
    </component>



You have the Money class. And that's it.
You don't need your UserType.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 8:48 am 
Newbie

Joined: Thu Dec 16, 2004 7:11 am
Posts: 7
snpesnpe: your suggestion to use CompositeUserType was right on target. Many thanks.


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