-->
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.  [ 7 posts ] 
Author Message
 Post subject: unable to compare dates in MySQL query
PostPosted: Wed Jan 21, 2004 2:11 pm 
Newbie

Joined: Wed Jan 21, 2004 1:59 pm
Posts: 5
I am unable to compare dates in MySQL queries. I'm trying to get all rows newer than a certain date by comparing the theDate column to a passed in parameter. I've tried explicitly stating the type in the mapping file with no luck. I was able to similarly compare integer fields, so I can't be too far off.

I keep getting the following error:

net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: 9, of class: com.mypackage.OtherClass

Perhaps there's a mapping error, but why would it give me an object not found error on a completely different class than the one I'm querying?

Here's more info:

from persisted bean class (called Bean)

private Date theDate;

from mapping file:

<property name="theDate"/>

GregorianCalendar cal = new GregorianCalendar();
cal.set(2003,1,1);
StringBuffer buffer = new StringBuffer("select bean from Bean bean where (bean.theDate) > :aDate");

... later ...

Query q = session.createQuery(buffer.toString());
q.setDate("aDate",cal.getTime());
results = q.list();

Any help appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 2:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I susspect you have an association mapped somewhere, where the foreign key constraint is not statisfied.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 2:50 pm 
Newbie

Joined: Wed Jan 21, 2004 1:59 pm
Posts: 5
[quote="gloeglm"]I susspect you have an association mapped somewhere, where the foreign key constraint is not statisfied.[/quote]

What's weird is that I'm able to compare an Integer attribute of the same class without problems.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 3:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Are you really loading exactly the same object(s) with both queries?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 3:30 pm 
Newbie

Joined: Wed Jan 21, 2004 1:59 pm
Posts: 5
[quote="gloeglm"]Are you really loading exactly the same object(s) with both queries?[/quote]

yeah, I just replaced the Date with an Integer attribute:

StringBuffer buffer = new StringBuffer("select bean from Bean bean where (bean.theInt) > :aInt");

... later ...

Query q = session.createQuery(buffer.toString());
q.setInteger("aInt",5);
results = q.list();


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 3:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Yes, but do they refer to exaclty the same row in your database?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 1:52 pm 
Newbie

Joined: Wed Jan 21, 2004 1:59 pm
Posts: 5
[quote="gloeglm"]Yes, but do they refer to exaclty the same row in your database?[/quote]

I played around some more, getting the Integer and Date comparison set up to return the same row, and have never seen the problem since (even with the original query that was causing the problem). I cannot explain why the problem occurred in the first place or why it is no longer happening, but I thank you for trying to help me out!


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