-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Criteria and sublass problem
PostPosted: Sat Oct 10, 2009 6:20 am 
Beginner
Beginner

Joined: Fri May 14, 2004 9:50 am
Posts: 28
Hello,

I'm using Hibernate 3.2.6 and Criteria API.

I have two class A and B. A has three subclass A', A'' and A'''.
In A'' and A''' I have a many-to-one to B.
In B I have a set of A objects.


<hibernate-mapping package="com...">
<class
name="B"
table="B"
>
<id
name="Id"
type="string"
column="B_ID"
>
<generator class="uuid"/>
</id>

<property
name="BDate"
column="B_DATE"
type="date"
not-null="true"
length="10"
update="false"
/>
...


<set
inverse="true"
lazy="true"
name="As" cascade="save-update">
<key column="B_ID" />
<one-to-many class="A" />
</set>
</class>

<hibernate-mapping package="com...">
<class name="A" table="A">
<id name="Id" type="string" column="A_ID">
<generator class="uuid" />
</id>
<discriminator column="A_DISCRIMINANT" type="string" />
<property name="AAmount" column="A_AMOUNT"
type="java.math.BigDecimal" not-null="true" length="12" />
...
<subclass name="A' " discriminator-value="A' ">
...
<many-to-one name="C" column="C_ID" class="C"
not-null="true">
</many-to-one>
</subclass>
<subclass name="A'' " discriminator-value="A'' ">
...
<many-to-one name="B" column="B_ID" class="B"
not-null="true" cascade="save-update">
</many-to-one>
</subclass>
<subclass name="A''' " discriminator-value="A''' ">
...
<many-to-one name="B" column="B_ID" class="B"
not-null="true" cascade="save-update">
</many-to-one>
</subclass>
</class>
</hibernate-mapping>

After that I create a criteria query :

DetachedCriteria criteria = DetachedCriteria.forClass(A.class,"a")
.createAlias("a.B", "b", CriteriaSpecification.LEFT_JOIN)
...;

When I do that Hibernate generate a query with the same join two times :
...
left outer join
B b2_
on a1_.B_ID=b2_.B_ID
left outer join
B b2_
on a1_.B_ID=b2_.B_ID

It results on a Mysql Exception Not unique table/alias: 'b2_'

It seems that it's due to the two many-to-one in the subclass. Is it a Criteria's bug ?

Thank's


Top
 Profile  
 
 Post subject: Re: Criteria and association->embedded->association problem
PostPosted: Fri Jul 23, 2010 12:11 pm 
Newbie

Joined: Sat Sep 10, 2005 3:05 am
Posts: 6
Location: Paris
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.

_________________
Antoine Herzog.
JBoss Portal and GateIn (JSR-286), JSF, Richfaces, J2EE, Drools, BRMS.
http://www.sysemo.com/Sysemo-expertise- ... portal.php


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.