-->
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.  [ 3 posts ] 
Author Message
 Post subject: Missing table reference in SQL (with joined-subclass)
PostPosted: Wed Jan 19, 2005 6:43 am 
Newbie

Joined: Wed Sep 29, 2004 10:36 am
Posts: 8
Location: Berlin, Germany
Hi there,

it seems that Hibernate generates a wrong SQL query (constructed from an HQL query) when I refer to a property of a mapped base class.

My HQL query is this:

Code:
from Client c where 1=1 and lower(c.person.email.email) like ?


The SQL displayed by Hibernate via show_sql is this:

Code:
Hibernate: select client0_.id as id, client0_.party_ref as party_ref from bo_Client client0_, bo_Person person1_, bo_Email email2_ where (1=1 )and(lower(email2_.email)like ?  and client0_.party_ref=person1_.id and person1__1_.email_ref=email2_.id) limit ?


As you can see, this query refers to "person1__1_" that wasn't defined before. Additionally the query should include the bo_Party table I believe (see mappings below).

Is there a workaround for this?

Thanks,
Oliver



Hibernate version: 2.1.7c

Mapping documents:
(excerpt)
Code:
<hibernate-mapping default-cascade="save-update">
   <class name="Party" table="bo_Party">
      <id name="id" type="int" column="id" unsaved-value="0">
         <generator class="native"/>
      </id>
      <many-to-one name="email" column="email_ref" class="Email" />
      <!-- more properties and associations ... -->
      <joined-subclass name="Person" table="bo_Person">
         <key column="id" />
         <!-- more properties and associations ... -->
      </joined-subclass>
      <joined-subclass name="Company" table="bo_Company">
         <key column="id" />
         <!-- more properties and associations ... -->
      </joined-subclass>
   </class>

   <class name="Email" table="bo_Email" lazy="true">
      <id name="id" type="int" column="id" unsaved-value="0" >
         <generator class="native"/>
      </id>
      <property name="email" column="email" type="string"/>
      <!-- more properties ... -->
   </class>
   
   <class name="Client" table="bo_Client" lazy="true">
      <id name="id" type="int" column="id" unsaved-value="0">
         <generator class="native"/>
      </id>
      <many-to-one name="person" column="party_ref" class="Person" not-null="true"/>
      <!-- more associations ... -->
   </class>

   <!-- more classes ... -->


Code between sessionFactory.openSession() and session.close():
I'm using the Spring framework. The relevant DAO lines are simply these:
Code:
// dynamically create a StringBuffer containing the HQL  [not shown]
Query query = getHibernateTemplate().createQuery(session, sb.toString());

// set parameters
int paramCount = params.size();
for (int i=0; i<paramCount; i++)
    query.setString(i, (String)params.get(i));

query.setFirstResult(firstIndex)
     .setMaxResults(maxResults);
return query.list();


Full stack trace of any exception that occurs:
(excerpt):

ERROR com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:80) - org.springframework.jdbc.UncategorizedSQLException: (Hibernate operation): encountered SQLException [General error, message from server: "Unknown table 'person1__1_' in where clause"]; nested exception is java.sql.SQLException: General error, message from server: "Unknown table 'person1__1_' in where clause"
javax.faces.el.EvaluationException: org.springframework.jdbc.UncategorizedSQLException: (Hibernate operation): encountered SQLException [General error, message from server: "Unknown table 'person1__1_' in where clause"]; nested exception is java.sql.SQLException: General error, message from server: "Unknown table 'person1__1_' in where clause"
[...]
Caused by: java.sql.SQLException: General error, message from server: "Unknown table 'person1__1_' in where clause"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1977)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1163)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1272)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2236)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1555)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:205)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:88)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1553)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)

Name and version of the database you are using:
MySQL 4.0.18

The generated SQL (show_sql=true):
see above


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 5:22 am 
Newbie

Joined: Wed Sep 29, 2004 10:36 am
Posts: 8
Location: Berlin, Germany
I've created a JIRA issue on this topic.

See http://opensource.atlassian.com/projects/hibernate/browse/HB-1406


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 8:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is a bug in 2.1 that was already fixed in the 3.0 branch. The workaround in 2.1 is to use an explicit join instead of an implicit join.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.