Dear all,
I'm having a strange behaviour using Hibernate Criteria API on entities sub-classes. Here is the testing I did:
I have the following entities:
- class User with attribute "name", "surname"
- class SpecificUser which is a sub-class of User class with "addresses" attribute which is mapped as a one-to-many Set (addresses Set<UserAddress>).
- Class UserAddress which contains attributes like street, etc.
Using Criteria API, I'm getting the following exception when I'm trying to query a one-to-many attribute on the sub-class:
Quote:
ERROR: table name "user1_" specified more than once
Here is the query:
Code:
Criteria criteria = session.createCriteria(User.class);
criteria.createCriteria("addresses").add(Restrictions.like("street", "Long Street%"));
This query only work when the first Criteria is defined as follow:
Code:
Criteria criteria = session.createCriteria(SpecificUser.class);
Looking to the SQL, it seems hibernate is doing the same join twice...
My inheritance mapping is done using "Table per class hierarchy" and I get no problem doing queries on other polymorphic associations...
Any hint is welcome !
Thanks in advance,
Joël