Hi I have this situation (using last Hibernate 4.1.7 Final version):
I have
Order class, when have association to
Client class, Client have to childrens
Person and
Company, both extending Client.
Person have associated
PersonData when I have some more informations about Person (historization is needed). Similar Company have associated
CompanyData. Tables are created what objects by per subclass mapping.
Now I want select orders by some kriteria, a then get Client, but only Person type and then his actualData (PersonData).
My select looks that (projection need some data from "PersonData", but first I trying generate correct joins) :
Code:
String par = "8%";
ProjectionList pl = Projections.projectionList();
pl.add(Projections.property("order.id"), "orderId");
pl.add(Projections.property("order.bookingsCode"), "bookingsCode");
pl.add(Projections.property("order.client"), "person");
DetachedCriteria cr = DetachedCriteria
.forClass(Order.class, "order")
.createAlias("order.client", "person", JoinType.INNER_JOIN,
Restrictions.eq("class", Person.class))
.createAlias("person.activeData", "adata")
.add(Restrictions.like("order.bookingsCode", par)).setProjection(pl)
.setResultTransformer(Transformers.aliasToBean(OrderView.class));
Interesant is what select that generate:
Code:
select
this_.idBook_order as y0_,
this_.bookings_code as y1_,
this_.idClient as y2_
from
book_order this_
inner join
crm_contact person1_
on this_.idClient=person1_.idCrm_contact
and (
person1_.type=?
)
inner join
crm_companyData adata2_
on person1_.idData=adata2_.idCrm_company
inner join
crm_personData adata2_
on person1_.idData=adata2_.idCrm_personData
where
this_.bookings_code like ?
and ofc I got error (database is MySQL):
Code:
org.hibernate.exception.SQLGrammarException: Not unique table/alias: 'adata2_'
Error is corect hibernate generate two inner joins with same alias. My questions are
1. I don't want that code in my select:
Quote:
inner join
crm_companyData adata2_
on person1_.idData=adata2_.idCrm_company
2. it's probably BUG when hibernate using same alias in 2 joins
thx any1 who will be help