use of org.hibernate.Criteria in project hibernate-orm by hibernate.
the class CriteriaQueryTranslator method getEntityName.
//TODO: use these in methods above
@Override
public String getEntityName(Criteria subcriteria, String propertyName) {
if (propertyName.indexOf('.') > 0) {
final String root = StringHelper.root(propertyName);
final Criteria crit = getAliasedCriteria(root);
if (crit != null) {
return getEntityName(crit);
}
}
return getEntityName(subcriteria);
}
use of org.hibernate.Criteria in project hibernate-orm by hibernate.
the class CriteriaQueryTranslator method getWholeAssociationPath.
private String getWholeAssociationPath(CriteriaImpl.Subcriteria subcriteria) {
String path = subcriteria.getPath();
// some messy, complex stuff here, since createCriteria() can take an
// aliased path, or a path rooted at the creating criteria instance
Criteria parent = null;
if (path.indexOf('.') > 0) {
// if it is a compound path
String testAlias = StringHelper.root(path);
if (!testAlias.equals(subcriteria.getAlias())) {
// and the qualifier is not the alias of this criteria
// -> check to see if we belong to some criteria other
// than the one that created us
parent = aliasCriteriaMap.get(testAlias);
}
}
if (parent == null) {
// otherwise assume the parent is the the criteria that created us
parent = subcriteria.getParent();
} else {
path = StringHelper.unroot(path);
}
if (parent.equals(rootCriteria)) {
// if its the root criteria, we are done
return path;
} else {
// otherwise, recurse
return getWholeAssociationPath((CriteriaImpl.Subcriteria) parent) + '.' + path;
}
}
use of org.hibernate.Criteria in project hibernate-orm by hibernate.
the class IdManyToOneTest method testCriteriaRestrictionOnIdManyToOne.
@Test
@TestForIssue(jiraKey = "HHH-7767")
public void testCriteriaRestrictionOnIdManyToOne() {
Session s = openSession();
s.beginTransaction();
s.createQuery("from Course c join c.students cs join cs.student s where s.name = 'Foo'").list();
Criteria criteria = s.createCriteria(Course.class);
criteria.createCriteria("students").createCriteria("student").add(Restrictions.eq("name", "Foo"));
criteria.list();
Criteria criteria2 = s.createCriteria(Course.class);
criteria2.createAlias("students", "cs");
criteria2.add(Restrictions.eq("cs.value", "Bar"));
criteria2.createAlias("cs.student", "s");
criteria2.add(Restrictions.eq("s.name", "Foo"));
criteria2.list();
s.getTransaction().commit();
s.close();
}
use of org.hibernate.Criteria in project hibernate-orm by hibernate.
the class JoinTest method testManyToOne.
@Test
public void testManyToOne() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Life life = new Life();
Cat cat = new Cat();
cat.setName("kitty");
cat.setStoryPart2("and the story continues");
life.duration = 15;
life.fullDescription = "Long long description";
life.owner = cat;
s.persist(life);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
Criteria crit = s.createCriteria(Life.class);
crit.createCriteria("owner").add(Restrictions.eq("name", "kitty"));
life = (Life) crit.uniqueResult();
assertEquals("Long long description", life.fullDescription);
s.delete(life.owner);
s.delete(life);
tx.commit();
s.close();
}
use of org.hibernate.Criteria in project hibernate-orm by hibernate.
the class ImmutableNaturalKeyLookupTest method getCriteria.
private Criteria getCriteria(Session s) {
Criteria crit = s.createCriteria(A.class, "anAlias");
crit.add(Restrictions.naturalId().set("name", "name1"));
crit.setFlushMode(FlushMode.COMMIT);
crit.setCacheable(true);
return crit;
}
Aggregations