Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HibernateException with setTimestamp but works with setParameter

Tags:

java

hibernate

Here's a minimal version of the code that took me a lot of time to figure out why it's not working:

Query q = session.createQuery(queryString);
q.setTimestamp(0, new java.util.Date());

 

The error was:

Unset positional parameter at position: 0

 

When I replaced setTimestamp() with setParameter():

Query q = session.createQuery(queryString);
q.setParameter(0, new java.util.Date());

 

And it worked, but I can't figure out why. I'm using hibernate 3.2.1.

EDIT: Where did the post with the other suggestion go? This was it!!

like image 614
Raidok Avatar asked Nov 18 '11 14:11

Raidok


1 Answers

There was a answer here previously that suggested to use java.sql.Timestamp instead of java.util.Date. With this little modification, the setTimestamp method works as expected.

like image 82
Raidok Avatar answered Nov 09 '22 19:11

Raidok