Hello,
this is an old post, but I have the same kind of problem.
with Hibernate 3.3.1
My classes contains an association->embedded->association
Class A contains a one to many association to B (a Set of B),
B contains a component embedded C,
C contains a many to one association to D (a reference tables).
all the association are FetchMode.LAZY (and must be lazy fetching).
I build a Criteria, with Subcriteria (Alias), to get all theses entities, with some aliases for B, and for D.
when trying to get the result, the SQL contains twice the outer join to D, with the same alias name.
and Hibernate then throws the exception :
Quote:
ERROR [JDBCExceptionReporter] Not unique table/alias: 'actyopdtkp5_'
("actyopdtkp5_" is the sql alias for D : it is created twice in the sql query.)
*********
I have tried several ways to get this Criteria working, but it either not work, or fall back to the doubling the outer join and alias, and error of "not unique table/alias".
I have tried to create an alias only for the D entity, but then the association path is B.C.D and Hibernate cannot translate the 2 level deep association path.
it ends with nothing in the SQL for the D entity (not fetched in the join).
*********
the problem seems to be : with an association -> embedded -> association, there must be two alias declared in the criteria :
B aliased B_alias
and
B_alias.C.D
and then, in the translator, it makes twice the association to D and adds a double SQL fragment of the outer join to the sql query.
I have looked in the translator, the way it does the sql (in debugging mode) : it create twice the association in the list of associations of the Criteria, then produces twice the sql fragment for the outer join.
*********
The only way it works : make only one alias (Subcriteria) for the B association, and set the fetchmode of D association as FetchMode.EAGER.
but that is not a good solution for the needs I have : D should not be fetched all the time.
*********
any idea what's going on ?
how to solve this ?
or to work around this problem ?
Is it a problem that is solved in Hib 3.5 ?
Thanks.