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.  [ 8 posts ] 
Author Message
 Post subject: Missing SQL join conditions when using discriminator subclas
PostPosted: Tue Jun 28, 2005 10:30 am 
Newbie

Joined: Tue Jun 28, 2005 6:27 am
Posts: 6
Hi everybody,

we have experienced what seems to be an Hibernate bug (we are using version 3.0.5) in the way Hibernate builds SQL join queries in certain circumstances. In detail: when a field of the HQL select clause refers to a many-to-one property and the HQL from clause contains more than one class, including a class mapped as a subclass (using discriminator) and this class is the LAST in the from list, the generated SQL queries miss the join conditions required to obtain the correct result.

In the following example 'role' is the many-to-one property and ProductionPlant is a subclass of Plant. The mapping files are the following:

<class name="Role" table="SCB_ROLE">
<id name="cod" column="ID">
<generator class="assigned"/>
</id>
<property name="desc" column="DESCRIPTION"/>
</class>

<class name="Plant" table="SCB_PLANT" discriminator-value="0">
<id name="cod" column="ID">
<generator class="assigned"/>
</id>
<discriminator column="TYPE" type="integer"/>
<property name="desc" column="DESCRIPTION"/>
<subclass name="ProductionPlant" discriminator-value="1"/>
<subclass name="MainPlant" discriminator-value="2"/>
</class>

<class name="User" table="SCB_USER">
<id name="cod" column="ID">
<generator class="assigned"/>
</id>
<property name="desc" column="DESCRIPTION"/>
<many-to-one name="role" column="ROLE"/>
</class>

And these are the queries:

Not working:

HQL: select u.role, p.cod from User as u, ProductionPlant as p
SQL: select user0_.ROLE as col_0_0_, production1_.ID as col_1_0_, role2_.ID as ID, role2_.DESCRIPTION as DESCRIPT2_1_ from SCB_USER user0_, SCB_ROLE role2_, SCB_PLANT production1_ where production1_.TYPE=1

Working:

HQL: select u.role, p.cod from ProductionPlant as p, User as u
SQL: select user1_.ROLE as col_0_0_, production0_.ID as col_1_0_, role2_.ID as ID, role2_.DESCRIPTION as DESCRIPT2_1_ from SCB_PLANT production0_, SCB_USER user1_, SCB_ROLE role2_ where production0_.TYPE=1 and user1_.ROLE=role2_.ID

As you can see, the order in which the classes appear in the from clause affects the generated SQL query.
Thank you for your attention.

Regards,

Lorenzo and Luca


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 11:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
(1) First test against current HB3 CVS (its probably already fixed)
(2) Submit a runnable test case to JIRA


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 11:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Actually, you don't even need CVS, just try the 3.1 preview that we put out last week.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 11:48 am 
Newbie

Joined: Tue Jun 28, 2005 6:27 am
Posts: 6
Thank you Gavin... we're just downloading the 3.1 preview... we'll let you now asap!

bye


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 12:27 pm 
Newbie

Joined: Tue Jun 28, 2005 6:27 am
Posts: 6
Hi,

we are very surprised to discover that Hibernate 3.1 requires JDK 1.5!!!

We cannot upgrade to JDK 1.5 ... (until enough application servers will be compliant with it) ...
Yes, you guessed, we don't work (only) with JBoss ... :-)

Any suggestion?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 12:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Um .... why do you think 3.1 requires JDK5? It does not...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 12:46 pm 
Newbie

Joined: Tue Jun 28, 2005 6:27 am
Posts: 6
Formally, we found it here:

http://sourceforge.net/project/shownotes.php?release_id=337385

Quote:
JDK 5.0 is required. If you are not using EJB3 persistence use Hibernate 3.0.x.


that is the README.TXT of the download ...

... and, trying to run a simple test with JDK 1.4.XX, we had the following Stack Trace

Code:
Exception in thread "main" java.lang.UnsupportedClassVersionError:
org/hibernate/Session (Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at test.Main.main(Main.java:33)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 4:19 am 
Newbie

Joined: Tue Jun 28, 2005 6:27 am
Posts: 6
OK, we get it. We recompiled Hibernate using JDK 1.4 and everything works fine
(maybe the statement "JDK 5.0 is required" refers to the jar included in the package, which is compiled with JDK 5).
The issue we had with polymorphic queries and many-to-ones seems to be resolved.
Thank you!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.