Hi,
My mappings are
Code:
<class name="Foo" table="FOO">
<id name="id">
<generator class="increment" />
</id>
<property name="text"/>
</class>
<class name="Bar" table="BAR">
<composite-id>
<key-many-to-one name="foo" class="Foo">
<column name="ID_FOO" />
</key-many-to-one>
</composite-id>
<property name="text"/>
</class>
I have the java classes that corresponds to these mappings.
I want to retrieve one Bar object so I have this code :
Code:
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(Foo.class);
criteria.add(Expression.eq("id", new Integer(1)));
Foo foo = (Foo) criteria.uniqueResult();
System.out.println("Foo :" + foo.getId());
criteria = session.createCriteria(Bar.class);
criteria.createCriteria("foo").add(Expression.eq("id", new Integer(1)));
Bar bar = (Bar) criteria.uniqueResult();
System.out.println("Bar :" + bar.getFoo().getId());
session.close();
Hibernate generates the sql code below :
Code:
select this.ID_FOO as ID_FOO0_, this.text as text0_ from BAR this where x0_.id=1
and I have an sql error.
With an HQL query like "from Bar bar where bar.foo.id=1" it works great.
So, it seems that there is a bug in the criteria API, isn't it ?
Seb