-->
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.  [ 4 posts ] 
Author Message
 Post subject: Order not working with nested properties
PostPosted: Thu May 26, 2005 1:38 pm 
Newbie

Joined: Fri Oct 29, 2004 4:20 pm
Posts: 16
Location: Grand Rapids, MI
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate doesn't seem to allow nested properties in an Order object.

Hibernate version:
3.0.5

Mapping documents:
<album.hbm.xml>
<hibernate-mapping package="ami.server.dto">
<class name="AlbumDTO" table="calliope.albums">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="title" column="title" not-null="true"/>
<property name="upc" column="upc" not-null="true"/>
<many-to-one name="artist" column="artist_id" class="ArtistDTO" fetch="join"/>
</class>
</hibernate-mapping>

<artist.hbm.xml>
<hibernate-mapping package="ami.server.dto">
<class name="ArtistDTO" table="calliope.artists">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name" column="name" not-null="true"/>
<property name="searchName" column="search_name" not-null="false"/>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Criteria criteria = s.createCriteria(AlbumDTO.class);
criteria.add(Example.create(obj));
criteria.addOrder(Order.asc("artist.name"));

Full stack trace of any exception that occurs:
No stack trace... just the following exception:

org.hibernate.QueryException: could not resolve property: artist.name of: ami.server.dto.AlbumDTO

Name and version of the database you are using:
MySQL 5.0.4 BETA

The generated SQL (show_sql=true):
No SQL is Generated

Debug level Hibernate log excerpt:
Nothing is really logged either... just the following line:

org.hibernate.QueryException: could not resolve property: artist.name of: ami.server.dto.AlbumDTO


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 2:53 pm 
Newbie

Joined: Fri Oct 29, 2004 4:20 pm
Posts: 16
Location: Grand Rapids, MI
The following hql query does work... which is what I would expect the previous example to generate.


String hql = "from AlbumDTO a order by a.artist.name";

return HibernateUtil.getSession().createQuery(hql).list();


Should this work with the Order object as well or have I found a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 4:01 pm 
Newbie

Joined: Fri Oct 29, 2004 4:20 pm
Posts: 16
Location: Grand Rapids, MI
This doesn't work either... with the same exception previously mentioned.

Criteria criteria = HibernateUtil.getSession().createCriteria(AlbumDTO.class);

criteria.add(Restrictions.isNotNull("artist.name"));

return criteria.list();


I'll pay $100 to anyone who can tell me how to get this functionality working other than manually writing HQL queries.


Top
 Profile  
 
 Post subject: Re: Order not working with nested properties
PostPosted: Thu May 26, 2005 4:54 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
searl001 wrote:
Code between sessionFactory.openSession() and session.close():
Criteria criteria = s.createCriteria(AlbumDTO.class);
criteria.add(Example.create(obj));
criteria.addOrder(Order.asc("artist.name"));


Have you tried something like this yet?

Code:
Criteria criteria = s.createCriteria(AlbumDTO.class);
criteria.add(Example.create(obj));
criteria.createCriteria("artist", "a").addOrder(Order.asc("a.name"));


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