-->
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: Date format : net.sf.hibernate.QueryException
PostPosted: Tue Oct 17, 2006 8:07 am 
Newbie

Joined: Tue Oct 17, 2006 7:58 am
Posts: 6
Hi,

I am trying to execute the following query with the following code.

public java.util.List getTasks() {
try {
Criteria crit = SessionFactoryUtils.getSession(getSessionFactory(), false).createCriteria(getReferenceClass());
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yy");
String myDate = formatter.format(date);
crit.createCriteria("TbReTask").add(Expression.lt("DueDate",myDate));
return crit.list();
}
catch (HibernateException ex) {
throw SessionFactoryUtils.convertHibernateAccessException(ex);
}
}

And I got the following error message


org.springframework.orm.hibernate.HibernateQueryException: could not resolve property:

Is it a probelm of date format and if the answer is yes, what should be the format. Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 11:06 am 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
What DB? What is db data type for column that contains dueDate? What datatype do you have this mapped to in Hibernate?

If your db datatype is date and the property datatype is Date and your dialect is correct, then you shouldn't need to format the date. Simply do something like:
Code:
crit.add(Expression.lt("dueDate", new Date()));


Curtis ...

_________________
---- Don't forget to rate! ----


Top
 Profile  
 
 Post subject: could not resolve property
PostPosted: Tue Oct 17, 2006 11:30 am 
Newbie

Joined: Tue Oct 17, 2006 7:58 am
Posts: 6
Hello again,

In fact I need to get the field DueDate which is the field of the table TbReTask (whose name is TB_RE_ES configured in the TbTask.hbm.xml file) referenced as followed.

<property
name="DueDate"
column="DUE_DATE"
type="date"
not-null="false"
length="7"
/>

The table TB_RE_TASK is referenced in the TbTask.hbm.xml file as followed

<set
name="TbRealEstates"
table="TB_RE_TASK"
cascade="all" lazy="true"
>
<key column="TASK_ID"/>
<many-to-many column="REAL_ESTATE_ID" class="TbRealEstate"/>
</set>

The code line where the problem is the following

crit.createCriteria("TbRealEstates").add(Expression.lt("DueDate",date));

The error message is

org.springframework.orm.hibernate.HibernateQueryException: could not resolve property: DueDate of: eu.cec.immogest.realestate.TbRealEstate; nested exception is net.sf.hibernate.QueryException: could not resolve property: DueDate of: eu.cec.immogest.realestate.TbRealEstate
net.sf.hibernate.QueryException: could not resolve property: DueDate of: eu.cec.immogest.realestate.TbRealEstate

The DueDate is not the field of the TbRealEstate table but is the field of the
table TbReTask which is the table between TbRealEstate and TbTask.


Top
 Profile  
 
 Post subject: net.sf.hibernate.QueryException
PostPosted: Wed Oct 18, 2006 9:04 am 
Newbie

Joined: Tue Oct 17, 2006 7:58 am
Posts: 6
We found out a solution in adding an entry in the the file TB_RE_TASK

<many-to-one
name="Task"
column="TASK_ID"
insert="false"
update="false"
class="TbTask"
not-null="false"
>

and another entry in the file TB_TASK

<set
inverse="true"
lazy="true"
name="TbReTasks"
>
<key column="TASK_ID" />
<one-to-many class="TbReTask" />
</set>

So, now this line of code is working

crit.createCriteria("TbReTasks").add(Expression.lt("DueDate",date));

So if a new table "C" is created coming from a relation x,n - x,n relation between table "A" and table "B" and if one or more field(s) is inserted in this table, the automatic generation of the hbm.xml file does not take into account the relation between table A and table C neither the relation between the table B and table C. And it is not possible to to filter on one of the C table fields, except if you insert by hand this relation.


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.