-->
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: Querying attributes of components by criteria
PostPosted: Tue May 09, 2006 1:12 pm 
Newbie

Joined: Tue Mar 21, 2006 7:18 pm
Posts: 13
Hi,

I'm using Hibernate 3.1

I have a problem with searching attriutes of components with the criteria API.

The class Annotation has a reference on the class Position. The class Position is mapped as a component of Annotation on the same table.

When I query like this:
Criteria lCrit = lSession.createCriteria(Annotation.class).createCriteria("position").add(Restrictions.like("x", "12"));

I get the following exception:
org.hibernate.QueryException: could not resolve property: x of: dms.Annotation

It seems like hibernate searches the attribute x in the class Annotation instead of Position.

Is there somewhere a mistake?

Thank you,

Jakob

here is the mapping:

<class name="dms.Annotation" table="ANNOTATION">
<id column="ID" name="id"/>
<discriminator column="ANNOTATION_TYPE" type="string"/>
<version column="VERSION" name="version"/>

<component class="dms.Position" name="position">
<property name="x">
<column name="X"/>
</property>
<property name="y">
<column name="Y"/>
</property>
</component>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 3:47 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
I thought that would work too but try

Code:
createCriteria(Annotation.class).createAlias("position", "pos").add(Restrictions.like("pos.x", "12"));



also, make sure position is defined as an attribute of Annotation class

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 6:32 pm 
Newbie

Joined: Tue Mar 21, 2006 7:18 pm
Posts: 13
Hi,

I already tried this. It causes the same Exception: "could not resolve property: x of: dms.Annotation

I made sure, Position is an attribute of Annotation.

Any other ideas?

------------

Jakob


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 9:59 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
It must be something to do with that component class being defined in the class Annotation. I've never used component classes. I don't know what, but I know the two ways you tried should work.

sorry

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 11:37 am 
Newbie

Joined: Tue Mar 21, 2006 7:18 pm
Posts: 13
Hi,

I found the solution accidentally.

When you query for an attribute of an component you have to write the attribute with a dot after the component.

So the correct query would look like:

session.createCriteria(Annotation.class).add(Restrictions.like("position.x", 12));

It's confusing, because I couldn't find this information nowhere.

Jakob


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.