Firstly I will explain my problem:
Following HQL works in the HQL-Editor:
select
count(*)
from
Consumerview
where
id.lastName in (
select
lastName
from
Psconsumer
where
status = 'loaded' and status in ('generated', 'loaded', 'locked', 'used', 'broken', 'saved') and isCompany= false)
The same HQL does not work within the Java Code. In the below code fragment
List result = session.createQuery(search).list();
the list is empty where search is the HQL.
Does anybody know the answer?
Hibernate version: 3.2.0
Mapping documents:
Code between sessionFactory.openSession() and session.close():
public static List executeSearch(String search) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List result = session.createQuery(search).list();
System.out.println("SEARCH: " + search);
// Workaround for Sessions Problem (lazy Initialization)
if ((!search.equals("from Status")) && (!search.equals("from Stati"))
&& (!search.contains("from Gisaddresses where status"))
&& (!search.contains("from Sim"))
&& (!search.contains("from Msisdn"))
&& (!search.contains("from Fln"))
&& (!search.contains("count(*) from Psconsumer"))
&& (!search.contains("from Bankaccountview"))
&& (!search.contains("Consumerview"))
&& (!search.contains("count(cons) from Psconsumer"))) {
System.out.println("Bin wieder drin!");
for (Iterator it = result.iterator(); it.hasNext();) {
Psconsumer psc = (Psconsumer) it.next();
Hibernate.initialize(psc);
Hibernate.initialize(psc.getAccounts());
Hibernate.initialize(psc.getBankAccounts());
Hibernate.initialize(psc.getGObjects());
Hibernate.initialize(psc.getPssubscriptions());
}
}
/*
* if((search.contains("from Addresses where status")) ){ for(Iterator
* it=result.iterator();it.hasNext();){ Addresses
* psc=(Addresses)it.next(); Hibernate.initialize(psc); } }
*/
session.getTransaction().commit();
// session.close();
return result;
}
Full stack trace of any exception that occurs:
Name and version of the database you are using: Oracle 9
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html