Hi,
maybe this is a known issue or I am doing something wrong, but I haven't been able to find an appropriate topic.
I need two attributes as the target of a property-ref from another class, so I am grouping them with <properties></properties>
Code:
<properties name="baureiheUndFabrikat" unique="true">
<property name="baureihe" type="string" column="baureihe" length="45"></property>
<many-to-one name="fabrikat" class="domain.Fabrikat" column="fabrikat" property-ref="name" not-found="ignore"></many-to-one>
</properties>
I have the following Criteria query:
Code:
@SuppressWarnings("unchecked")
public List<Baureihe> findByExample(Baureihe baureihe, int start,
int pageSize) {
Criteria crt = createExampleCriteria(baureihe);
crt.setFirstResult(start);
crt.setMaxResults(pageSize);
return crt.list();
}
public Integer getNumberByExample(Baureihe baureihe) {
Criteria crt = createExampleCriteria(baureihe);
crt.setProjection(Projections.rowCount());
return (Integer) crt.uniqueResult();
}
private Criteria createExampleCriteria(Baureihe baureihe) {
Example example = Example.create(baureihe).ignoreCase().enableLike(MatchMode.ANYWHERE);
Criteria crt = sessionFactory.getCurrentSession().createCriteria(Baureihe.class);
crt.add(example);
if (baureihe.getFabrikat() != null)
crt.createCriteria("fabrikat").add(Example.create(baureihe.getFabrikat()));
if (baureihe.getFahrzeugtyp() != null)
crt.createCriteria("fahrzeugtyp").add(Example.create(baureihe.getFahrzeugtyp()));
if (baureihe.getHersteller() != null)
crt.createCriteria("hersteller").add(Example.create(baureihe.getHersteller()));
return crt;
}
These two queries are used for filtering the results and paging.
If the "fabrikat" is set I get an error that the column "name" of "fabrikat" is unknown, but it does exist.
It works fine if I move the <many-to-one> outside of the <properties>, so the problem is only occuring when <properties> is used.
From the hibernate documentation I understand that <properties> is just a grouping and useful to have multiple properties as the target of a property-ref, exactly what I am doing.
Is the syntax of my criteria query wrong and I have to use the name of my <properties> element or is this a bug?
edit: I am using version 3.3.2 of hibernate
Thank you
Best regards
Tobias