I have a problem with a Criteria query.
In an other method I use HQL query in order to remove some objects in database.
The query works.
In another method I do, actually, Criteria query which get objects.
When i get objects , they are not synchronized to the database.
So
1. How synchronized this criteria query in roder to get REAL objects?
2. If 1. is not possible, i want to transform Criteria query to HQL
Here my criteria query:
final Criteria crit = session.createCriteria(ObjectDao.class);
if (clientName != null && clientName.length() > 0) {
crit.createAlias("objectType.client", "client");
crit.add(Restrictions.eq("client.name", clientName));
}
if (objectType != null && objectType.length() > 0) {
crit.createAlias("objectType", "objectType");
crit.add(Restrictions.eq("objectType.type", objectType));
}
final List<ObjectDao> ret = crit.list();
And HQl transformed query which dont work
String hqlQuery = "select ObjectDao where objectType.client.name = :clientName";
Query query = session.createQuery(hqlQuery)
// .setParameter("objectList", objectType)
.setParameter("clientName", clientName);
final List<ObjectDao> ret2 = query.list();
Thanks!
Looks like you are using Level 2 cache. If so this will not work either.