-->
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: Criteria.list() producing nothing on 2nd query
PostPosted: Tue Aug 14, 2007 10:57 am 
Newbie

Joined: Tue Aug 14, 2007 10:32 am
Posts: 1
Location: Kent, England
New to Hibernate and working with WSAD/Eclipse, mySQL, Tomcat, Hibernate latest version, l3po connection pooling.

1. First query works fine and produces expected result:

Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List l = new ArrayList();

try {
l = session.createCriteria(Users.class)
.add( Restrictions.eq("user_id", uid))
.add( Restrictions.eq("password", pw))
.list();
if (l.size() <= 0) return false;
if (l.size() > 1) {
System.out.println("System error");
return false;
}

} catch (HibernateException he) {
System.out.println("HIbernateException--->" + he);
}
session.getTransaction().commit();

2. Second query produces nothing

Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();

List ctl = new ArrayList();
try {
Criteria crit = session.createCriteria(CodeType.class)
.add( Restrictions.eq("site_id", site_id));
ctl = crit.list();
System.out.println("list size is " + ctl.size());
} catch (HibernateException he) {
System.out.println("HibernateException--->" + he);
}

session.getTransaction().commit();

Examining the Tomcat console log there appears to be no SQL activity from the list() as there was with the first query. Log extract:

15753 [http-8080-Processor3] DEBUG org.hibernate.impl.SessionImpl - opened session at timestamp: 11870998789
15753 [http-8080-Processor3] DEBUG org.hibernate.context.ThreadLocalSessionContext - allowing method [beginTransaction] in non-transacted context
15753 [http-8080-Processor3] DEBUG org.hibernate.context.ThreadLocalSessionContext - allowing proxied method [beginTransaction] to proceed to real session
15753 [http-8080-Processor3] DEBUG org.hibernate.transaction.JDBCTransaction - begin
15753 [http-8080-Processor3] DEBUG org.hibernate.jdbc.ConnectionManager - opening JDBC connection
15753 [http-8080-Processor3] DEBUG com.mchange.v2.resourcepool.BasicResourcePool - resource age is okay: com.mchange.v2.c3p0.impl.NewPooledConnection@13829d5 ---> age: 1292 max: 5000000 [com.mchange.v2.resourcepool.BasicResourcePool@1b6634c]
15753 [http-8080-Processor3] DEBUG com.mchange.v2.resourcepool.BasicResourcePool - trace com.mchange.v2.resourcepool.BasicResourcePool@1b6634c [managed: 2, unused: 1, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@13829d5)
15753 [http-8080-Processor3] DEBUG org.hibernate.transaction.JDBCTransaction - current autocommit status: false
15753 [http-8080-Processor3] DEBUG org.hibernate.jdbc.JDBCContext - after transaction begin
15753 [http-8080-Processor3] DEBUG org.hibernate.context.ThreadLocalSessionContext - allowing proxied method [createCriteria] to proceed to real session
list size is 0
15763 [http-8080-Processor3] DEBUG org.hibernate.context.ThreadLocalSessionContext - allowing proxied method [flush] to proceed to real session
15763 [http-8080-Processor3] DEBUG org.hibernate.context.ThreadLocalSessionContext - allowing proxied method [getTransaction] to proceed to real session
15763 [http-8080-Processor3] DEBUG org.hibernate.transaction.JDBCTransaction - commit
15763 [http-8080-Processor3] DEBUG org.hibernate.impl.SessionImpl - automatically flushing session
15763 [http-8080-Processor3] DEBUG org.hibernate.jdbc.JDBCContext - before transaction completion
15763 [http-8080-Processor3] DEBUG org.hibernate.impl.SessionImpl - before transaction completion
15763 [http-8080-Processor3] DEBUG org.hibernate.transaction.JDBCTransaction - committed JDBC Connection
15763 [http-8080-Processor3] DEBUG org.hibernate.jdbc.JDBCContext - after transaction completion
15763 [http-8080-Processor3] DEBUG org.hibernate.jdbc.ConnectionManager - aggressively releasing JDBC connection
15763 [http-8080-Processor3] DEBUG org.hibernate.jdbc.ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
15763 [http-8080-Processor3] DEBUG com.mchange.v2.c3p0.stmt.GooGooStatementCache - checkinAll(): com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 1; checked out: 0; num connections: 1; num keys: 1
15763 [http-8080-Processor3] DEBUG com.mchange.v2.resourcepool.BasicResourcePool - trace com.mchange.v2.resourcepool.BasicResourcePool@1b6634c [managed: 2, unused: 1, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@13829d5)
15763 [http-8080-Processor3] DEBUG org.hibernate.impl.SessionImpl - after transaction completion
15763 [http-8080-Processor3] DEBUG org.hibernate.impl.SessionImpl - automatically closing session
15763 [http-8080-Processor3] DEBUG org.hibernate.impl.SessionImpl - closing session
15763 [http-8080-Processor3] DEBUG org.hibernate.jdbc.ConnectionManager - connection already null in cleanup : no action

Sincere thanks in advance for any assistance


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 15, 2007 2:07 am 
Newbie

Joined: Thu Aug 09, 2007 9:37 pm
Posts: 5
you chect the method getCurrentSession() method in HibernateUtil

_________________
sriram


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 15, 2007 2:08 am 
Newbie

Joined: Thu Aug 09, 2007 9:37 pm
Posts: 5
you check getCurrentSession() in HibernateUtil

_________________
sriram


Top
 Profile  
 
 Post subject: Criteria.list() producing nothing on 2nd query
PostPosted: Sun Mar 02, 2008 7:14 pm 
Newbie

Joined: Sun Nov 25, 2007 2:59 pm
Posts: 1
Did you get an answer on this?
I am seeing exactly the same behaviour against a MySQL database.
In my case one of my columns includes a space and is escaped with `case number` in the file

I have switched the hibernate debug logging on and I get this:
Code:
23:09:03,296 DEBUG ifs:446 - custActions pre crit case number: 0085485 office: BIR
23:09:03,296 DEBUG ThreadLocalSessionContext:300 - allowing proxied method [createCriteria] to proceed to real session
23:09:03,328 DEBUG ifs:451 - custActions post crit case number: 0085485 office: BIR

The two IFS lines indicate the text before and after the criteria commands see here:
        log.debug("custActions pre crit case number: "+caseNo+" office: "+office);
        Criteria crit = session.createCriteria(CustomeractionsId.class);
        crit.add( Restrictions.like("casenumber", caseNo, MatchMode.END) );
      crit.add( Restrictions.like("office", office, MatchMode.END) );
      List result = crit.list();
        log.debug("custActions post crit case number: "+caseNo+" office: "+office);


Does this correspond to any of your code/issues?
[/code]


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.