-->
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.  [ 3 posts ] 
Author Message
 Post subject: criteria when using component
PostPosted: Mon Jan 10, 2011 8:39 am 
Newbie

Joined: Tue Dec 14, 2010 7:48 am
Posts: 10
I try use criteria to search with component field. example

class House
public class House {

private int id;

private String ower;

private Adress adress;

getter....
setter.....
}
class Adress
public class Adress{
private String street;
private String city;
}

My House table
SCM_HOUSE
ID int
OWER varchar2(50)
STREET varchar2(50)
CITY varchar2(30)


House.hbm.xml
<hibernate-mapping>
<class name="com.scm.model.House" table="SCM_HOUSE" schema="SCM">
<id name="id" type="long">
<column name="ID_HOUSE" precision="22" scale="0" />
<generator class="increment"/>
</id>

<component name="adress" class="com.scm.model.Adress">
<property name="street">
<column name="STREET />
</property>
<property name="city">
<column name="CITY" />
</property>
</component>

<property name="ower">
<column name="OWER" />
</property>
</class>
</hibernate-mapping>

when I try do this:

session = getHibernateTemplate().getSessionFactory().openSession();
Criteria criteria = session.createCriteria(clazz);
criteria.add(Expression.eq("ower", "paul"));

Criteria criteriaAdress = criteria.createCriteria("adress");
criteriaAdress.add(Expression.eq("city", "alabama"));
Collection result = criteria.list();

I get this error: could not resolve property: city of: com.scm.modelo.House.
but if I am not use component field, if a use a
relationship one to one or some other, I get sucess in my operation.so this problem occurs only if I use a component field (agregate) in my class.

some body knows how can I resolve this problem???


Report this post


Top
 Profile  
 
 Post subject: Re: criteria when using component
PostPosted: Tue Jan 11, 2011 1:50 am 
Newbie

Joined: Tue Dec 14, 2010 7:48 am
Posts: 10
pleaseeeeeeeee help me


Top
 Profile  
 
 Post subject: Re: criteria when using component
PostPosted: Tue Jan 11, 2011 6:09 am 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
I haven't use this, but what I think you are doing wrong is, that Adress is not mapped, it is just a component.

Maybe, it should be something like this?

criteria.add(Expression.eq("adress.city", "alabama"));

Collection result = criteria.list();


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