-->
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: Problem with HQL query related to inheritance
PostPosted: Tue Jan 25, 2005 10:42 pm 
Newbie

Joined: Wed Dec 29, 2004 8:07 pm
Posts: 4
Location: Mérida, Yucatán, México
Hi:

I have a class Car, this class has a propierty owner which is a reference a class Person, which class has a reference a class Address which has a String Street.
I have a class Company, which has a reference a class Employee which extends Person.

When I want to execute session.find("from Company as c where c.employee.address.street = '30'"); its fails.
But I execute session.find("from Employee as e where e.address.street = '30'"); it works!.
And I execute session.find("from Car as c where c.owner.address.street = '30'"); also its works!.
This happens in all my classes whose relations are similar.

Can you help me please?

Here its the class diagram
Image


Hibernate version:
2.1.2


Mapping documents:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class name="test.Address" table="address">
       <cache usage="read-write"/>
       
        <id name="id" unsaved-value="0" type="integer">
            <generator class="identity"/>
        </id>
        <property name="street"/>
    </class>

</hibernate-mapping>


Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class name="test.Person" table="person">
       <cache usage="read-write"/>
       
        <id name="id" unsaved-value="0" type="integer">
            <generator class="identity"/>
        </id>
        <property name="name"/>
       
        <many-to-one name="address" class="test.Address" column="Address_id" unique="true" cascade="all"/>
       
       
        <joined-subclass name="test.Employee" extends="test.Person" table="employee">
          <key column="Person_id"/>
          <property name="pay"/>
       </joined-subclass>
       
    </class>

</hibernate-mapping>



Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class name="test.Car" table="car">
       <cache usage="read-write"/>
        <id name="id" unsaved-value="0" type="integer">
            <generator class="identity"/>
        </id>
       
        <many-to-one name="owner" class="test.Person" column="Person_id"/>
    </class>
</hibernate-mapping>



Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class name="test.Company" table="company">
       <cache usage="read-write"/>
        <id name="id" unsaved-value="0" type="integer">
            <generator class="identity"/>
        </id>
       
        <many-to-one name="employee" class="test.Employee" column="Employee_Person_id"/>
    </class>
</hibernate-mapping>




Code between sessionFactory.openSession() and session.close():

Code:
tx = session.beginTransaction();
         
         list = session.find("from Company as c where c.employee.address.street = '30'");
         
         tx.commit();



Full stack trace of any exception that occurs:

INFO - Hibernate 2.1.2
INFO - hibernate.properties not found
INFO - using CGLIB reflection optimizer
INFO - configuring from resource: /hibernate.cfg.xml
INFO - Configuration resource: /hibernate.cfg.xml
INFO - Mapping resource: test/Person.hbm.xml
INFO - Mapping class: test.Person -> person
INFO - Mapping joined-subclass: test.Employee -> employee
INFO - Mapping resource: test/Address.hbm.xml
INFO - Mapping class: test.Address -> address
INFO - Mapping resource: test/Company.hbm.xml
INFO - Mapping class: test.Company -> company
INFO - Mapping resource: test/Car.hbm.xml
INFO - Mapping class: test.Car -> car
INFO - Configured SessionFactory: null
INFO - processing one-to-many association mappings
INFO - processing one-to-one association property references
INFO - processing foreign key constraints
INFO - Using dialect: net.sf.hibernate.dialect.MySQLDialect
INFO - Use outer join fetching: true
INFO - Using Hibernate built-in connection pool (not for production use!)
INFO - Hibernate connection pool size: 20
INFO - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/testHibernate
INFO - connection properties: {user=root, password=}
INFO - Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactory
INFO - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
INFO - Use scrollable result sets: true
INFO - Use JDBC3 getGeneratedKeys(): true
INFO - Optimize cache for minimal puts: false
INFO - echoing all SQL to stdout
INFO - Query language substitutions: {}
INFO - cache provider: net.sf.hibernate.cache.HashtableCacheProvider
INFO - instantiating and configuring caches
INFO - building session factory
INFO - no JNDI name configured
Hibernate: select company0_.id as id, company0_.Employee_Person_id as Employee2_ from company company0_, employee employee1_, address address2_ where (address2_.street='30' and company0_.Employee_Person_id=employee1_.Person_id and employee1__1_.Address_id=address2_.id)
WARN - SQL Error: 1109, SQLState: S1000
ERROR - General error, message from server: "Unknown table 'employee1__1_' in where clause"
WARN - SQL Error: 1109, SQLState: S1000
ERROR - General error, message from server: "Unknown table 'employee1__1_' in where clause"
ERROR - Could not execute query
java.sql.SQLException: General error, message from server: "Unknown table 'employee1__1_' in where clause"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1825)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1020)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1109)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2030)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1563)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:795)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:950)
at net.sf.hibernate.loader.Loader.list(Loader.java:941)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1491)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1483)
at test.Tester.query(Tester.java:236)
at test.Tester.main(Tester.java:62)
Could not execute query


Name and version of the database you are using:
Mysql 4.0


The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 26, 2005 3:40 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
have you tried to upgrade your hibernate version.
let's test it again with 2.1.7c

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 26, 2005 3:39 pm 
Newbie

Joined: Wed Dec 29, 2004 8:07 pm
Posts: 4
Location: Mérida, Yucatán, México
thanks for you answer Anthony.

I tested with 2.1.7c and also its fail.

But I tested with 3.0 beta 2 and its works!!!

A thing forgot to me to mention is that I use the table-per-subclass mapping strategy, therefore I don't use the discriminator element.

will be this the reason?

thank you very much by your interest!!!


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.