-->
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: Criteria order and underscore bug?
PostPosted: Mon Jan 23, 2012 7:16 am 
Newbie

Joined: Mon Jan 23, 2012 6:56 am
Posts: 1
Hi,

I have come what seems like a bug...

I have a class User which contains the column:
Code:
@Column(name = "some_date", nullable = true)
public Date getSomeDate( ) {
  return someDate;
}


Order the results like so:
Code:
Criteria criteria = sessionFactory.getCurrentSession( ).createCriteria( User.class );
criteria.addOrder( Order.asc( "some_date" ) );


Hibernate throws the exception:
Code:
org.hibernate.QueryException: could not resolve property: some_date of: com.test.User
   at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:81)
   at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:75)
   at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1468)
   at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:62)
   at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1443)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:483)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumnsUsingProjection(CriteriaQueryTranslator.java:443)
   at org.hibernate.criterion.Order.toSqlString(Order.java:68)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getOrderBy(CriteriaQueryTranslator.java:394)
   at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:114)
   at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:83)
   at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:92)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1687)
   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
...


When removing the underscores from the column name and order query, everything works fine. So, it appears hibernate does not like underscores when ordering, has anyone come across this issue?

I'm using hibernate version 3.5.6-Final.


Top
 Profile  
 
 Post subject: Re: Criteria order and underscore bug?
PostPosted: Tue Jan 24, 2012 3:12 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
You have to use the property name not the column name! The property is named "someDate", so you have to use "someDate". (Maybe Hibernate is case-insensitive here. We ALWAYS use the exact capitalization of our properties.)


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.