I have a class called User, which has a few properties. One of the properties
is last time a user logged into the application. I am writing some code for
searching for users who logged into the application before a certain time point.
I use Hibernate's Example and Criteria to build the query code as follows:
Example exampleUser = Example.create(user).ignoreCase().enableLike(MatchMode.ANYWHERE);
SimpleDateFormat dateFormat = new SimpleDateFormat("mm/dd/yyyy HH:mm:ss");
Criteria crit = this.getSession().createCriteria(User.class).add(exampleUser);
crit.add(Expression.le("lastLogin", "'12/11/2005 11:11:11'"));
return crit.list();
When the code runs to "return crit.list()", there is the following exception thrown:
10:34:37,437 WARN AbstractBatcher:208 - exception clearing maxRows/queryTimeout
java.sql.SQLException: Invalid state, the PreparedStatement object is closed.
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.checkOpen(JtdsPreparedStatement.java:181)
at net.sourceforge.jtds.jdbc.JtdsStatement.getMaxRows(JtdsStatement.java:671)
at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:204)
at org.hibernate.jdbc.AbstractBatcher.closeStatements(AbstractBatcher.java:254)
at org.hibernate.jdbc.ConnectionManager.cleanup(ConnectionManager.java:259)
at org.hibernate.jdbc.ConnectionManager.close(ConnectionManager.java:194)
at org.hibernate.impl.SessionImpl.close(SessionImpl.java:289)
at org.springframework.orm.hibernate3.SessionFactoryUtils.doClose(SessionFactoryUtils.java:751)
at org.springframework.orm.hibernate3.SessionFactoryUtils.closeSessionOrRegisterDeferredClose(SessionFactoryUtils.java:740)
at org.springframework.orm.hibernate3.SessionFactoryUtils.releaseSession(SessionFactoryUtils.java:720)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCleanupAfterCompletion(HibernateTransactionManager.java:568)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.cleanupAfterCompletion(AbstractPlatformTransactionManager.java:607)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:487)
at org.springframework.transaction.interceptor.TransactionAspectSupport.doCloseTransactionAfterThrowing(TransactionAspectSupport.java:278)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy17.findUsers(Unknown Source)
....
Did some research but got no clue....Is the above code right? Any help/info is greatly appreciated!
I am using Hibernate 3.0.3 and MS SQL server.
Thanks,
Pete
|