[Hibernate-JIRA] Created: (HHH-2529) HQL resulting in incorrect SQL caused by ORDER BY
by Marc Luce (JIRA)
HQL resulting in incorrect SQL caused by ORDER BY
-------------------------------------------------
Key: HHH-2529
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2529
Project: Hibernate3
Issue Type: Bug
Components: query-hql
Affects Versions: 3.2.2
Environment: hibernate-3.2.2, Sybase Adaptive Server 12.5
Reporter: Marc Luce
Priority: Minor
Attachments: SimpleHibernateTest.zip
I have written a HQL query that retrieves a set of objects that are mapped from a parent object. The SQL that is generated from it is incorrect. I have discovered that the ORDER BY clause is causing the problem. I will include the HQL that generates the incorrect join in SQL and the HQL that generates the correct join in SQL (without an ORDER BY). The first query results in a query that returns each object 3 times. If I remove the ORDER BY clause, I will receive the correct result set, but obviously, it would be unordered.
The HQL:
SELECT b.loans FROM Batch AS b WHERE b.id = :id ORDER BY b.loans.loanNumber DESC
The SQL that is generated:
select
loan2_.id as id2_,
loan2_.name as name2_
from
dbo.TestBatch batch0_
inner join
TestMapping loans1_
on batch0_.id=loans1_.batchId
inner join
dbo.TestLoan loan2_
on loans1_.loanId=loan2_.id,
TestMapping loans3_,
dbo.TestLoan loan4_
where
batch0_.id=loans3_.batchId
and loans3_.loanId=loan4_.id
and batch0_.id=?
order by
loan4_.name DESC
The mapping:
<class name="testHibernate.Batch"
table="TestBatch"
schema="dbo"
dynamic-insert="true"
dynamic-update="true">
<id name="id" type="java.lang.Integer" column="id" >
<generator class="increment" />
</id>
<property name="name" type="java.lang.String" column="name" length="80" not-null="true" />
<set name="loans" table="TestMapping">
<key column="batchId"/>
<many-to-many column="loanId" unique="true" class="testHibernate.Loan" lazy="proxy"/>
</set>
</class>
<class name="testHibernate.Loan"
table="TestLoan"
schema="dbo"
dynamic-insert="true"
dynamic-update="true">
<id name="id" type="java.lang.Integer" column="id" >
<generator class="increment" />
</id>
<property name="loanNumber" type="java.lang.String" column="name" length="80" not-null="true" />
</class>
I will also attach a zip of my very simple eclipse project that illustrates the problem.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
17 years, 9 months
[Hibernate-JIRA] Created: (HBX-819) NullPointerException in simple case with one configuration file and two console configurations
by Francois Granade (JIRA)
NullPointerException in simple case with one configuration file and two console configurations
----------------------------------------------------------------------------------------------
Key: HBX-819
URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-819
Project: Hibernate Tools
Type: Bug
Components: consoleconfiguration
Versions: 3.2beta8
Environment: macos, hsqldb
Reporter: Francois Granade
Priority: Minor
I'm having an NullPointerException (See the stack below), I'm not really able to understand what triggers it (it is not completely reproducible, it seems).
My setup is very simple: just one Java project, one hibernate configuration file, two console configurations, nothing else. The only thing that's a little special, is that one of the console configuration is invalid (no driver jar file defined).
I'll try to describe it as precisely as possible:
- I have a very simple HSQLDB server, just out-of-the box. I have created only one table with: "create table x (a varchar(255), b int)".
- I created an Hibernate configuration file for the HSQLDB database using "File > New > Others", "Hibernate > Hibernate configuration file"; I specified "create a console configuration", and I gave a name to the Console Configuration, but I didn't set any other property (in particular, I did not specify the .jar file for hsqldb: so it's not a correctly defined console configuration)
- Then I created a second console configuration; That time, in the 'classpath' section at the bottom, I selected 'add external jar' and added my 'hsqldb.jar'.
- I can now open the HSQL DB correctly in the Hibernate Configuration view, with this second console configuration (the first one is doing an error, which is normal).
- now, time to time, when I right-click on the definition of my table ('X"), and select "HQL Editor", I sometimes get the NullPointerException (but not always).
here's the stack trace:
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.ui.workbench".
!STACK 0
java.lang.NullPointerException
at java.util.TreeMap.compare(TreeMap.java:1093)
at java.util.TreeMap.getEntry(TreeMap.java:347)
at java.util.TreeMap.get(TreeMap.java:265)
at org.hibernate.console.KnownConfigurations.find(KnownConfigurations.java:225)
at org.hibernate.eclipse.console.AbstractQueryEditor.getConsoleConfiguration(AbstractQueryEditor.java:51)
at org.hibernate.eclipse.console.views.DynamicSQLPreviewView.updateText(DynamicSQLPreviewView.java:137)
at org.hibernate.eclipse.console.views.DynamicSQLPreviewView.setCurrentEditor(DynamicSQLPreviewView.java:130)
at org.hibernate.eclipse.console.views.DynamicSQLPreviewView.hookIntoEditor(DynamicSQLPreviewView.java:114)
at org.hibernate.eclipse.console.views.DynamicSQLPreviewView.access$2(DynamicSQLPreviewView.java:107)
at org.hibernate.eclipse.console.views.DynamicSQLPreviewView$1.partBroughtToTop(DynamicSQLPreviewView.java:92)
at org.eclipse.ui.internal.PartListenerList2$2.run(PartListenerList2.java:83)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:843)
at org.eclipse.ui.internal.PartListenerList2.fireEvent(PartListenerList2.java:53)
at org.eclipse.ui.internal.PartListenerList2.firePartBroughtToTop(PartListenerList2.java:81)
at org.eclipse.ui.internal.PartService.firePartBroughtToTop(PartService.java:90)
at org.eclipse.ui.internal.WWinPartService$1.partBroughtToTop(WWinPartService.java:40)
at org.eclipse.ui.internal.PartListenerList2$2.run(PartListenerList2.java:
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
17 years, 9 months