-->
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: SQL generation error, column in wrong class
PostPosted: Thu Jan 31, 2008 10:28 am 
Newbie

Joined: Wed Jan 23, 2008 3:40 pm
Posts: 7
Location: Tennessee
The mapping is straight forward but why does Hib think the supervisor id is in the user table/class? If I retrieve an employee the supervisor is a valid employee.

Hibernate version:
3.2
Mapping documents:
<hibernate-mapping>
<class name="com.javalobby.tnt.domain2.User" table="USER" lazy="true">
<id name="id" type="long" column="user_id">
<generator class="identity" />
</id>
<discriminator column="type" type="string"/>
<property name="firstName" column="first_name"/>
<property name="lastName" column="last_name"/>
<subclass name="com.javalobby.tnt.domain2.Employee" discriminator-value="employee">
<join table="employee">
<key column="employee_id"/>
<property name="jobTitle" column="job_title"/>
<many-to-one name="supervisor" column="supervisor_id" not-null="true" />
</join>
<subclass name="com.javalobby.tnt.domain2.Employer" discriminator-value="employer">
<set name="subordinates" >
<key column="supervisor_id" not-null="true" />
<one-to-many class="com.javalobby.tnt.domain2.Employee"/>
</set>
<join table="employer">
<key column="employer_id"/>
<property name="companyCarBrand" column="company_car_brand"/>
</join>
</subclass>
</subclass>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Session session = HibernateSessionFactory.currentSession();

try {
Employer empr = (Employer)session.load(Employer.class, new Long(1));
System.out.println(empr);
System.out.println(empr.getSubordinates().size());
}
catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


finally {
session.close();
}


Full stack trace of any exception that occurs:

Name and version of the database you are using:
mysql 5
The generated SQL (show_sql=true):
Hibernate: select employer0_.user_id as user1_0_0_, employer0_.first_name as first3_0_0_, employer0_
.last_name as last4_0_0_, employer0_1_.job_title as job2_1_0_, employer0_1_.supervisor_id as supervi
sor3_1_0_, employer0_2_.company_car_brand as company2_2_0_ from USER employer0_ inner join employee
employer0_1_ on employer0_.user_id=employer0_1_.employee_id inner join employer employer0_2_ on empl
oyer0_.user_id=employer0_2_.employer_id where employer0_.user_id=? and employer0_.type='employer'
Class: class com.javalobby.tnt.domain2.Employer
ID: 1
First Name: R.J.
Last Name: Lorimer
Last Version: 0
Job Title: Master of All
Supervisor: null
Company Car Brand: Ferrari
Hibernate: select subordinat0_.supervisor_id as supervisor5_1_,
subordinat0_.user_id as user1_1_,
subordinat0_.user_id as user1_0_0_,
subordinat0_.first_name as first3_0_0_,
subordinat0_.last_name as last4_0_0_,
subordinat0_1_.job_title as job2_1_0_,
subordinat0_1_.supervisor_id as supervisor3_1_0_,
subordinat0_2_.company_car_brand as company2_2_0_, subordinat0_.type as type0_0_
from USER subordinat0_ inner join employee subordinat0_1_ on subordinat0_.user_id=subordinat0_1_.employee_id left outer join employer subordinat0_2_ on subordinat0_.user_id=subordinat0_2_.employer_id
where subordinat0_.supervisor_id=?
08:06:01,240 WARN JDBCExceptionReporter:77 - SQL Error: 1054, SQLState: 42S22
08:06:01,240 ERROR JDBCExceptionReporter:78 - Unknown column 'subordinat0_.supervisor_id' in 'field
list'
o
Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html

_________________
Jack


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 12:35 pm 
Newbie

Joined: Wed Jan 23, 2008 3:40 pm
Posts: 7
Location: Tennessee
When I change the mapping to this it works. Is <subclass> not working like <joined-class> for collections??

<hibernate-mapping>
<class name="com.javalobby.tnt.domain2.User" table="USER" lazy="true">
<id name="id" type="long" column="user_id">
<generator class="identity" />
</id>
<property name="firstName" column="first_name"/>
<property name="lastName" column="last_name"/>
<joined-subclass name="com.javalobby.tnt.domain2.Employee" table="employee">
<key column="employee_id"/>
<property name="jobTitle" column="job_title"/>
<many-to-one name="supervisor" column="supervisor_id" not-null="true" insert="false" update="false"/>
<joined-subclass name="com.javalobby.tnt.domain2.Employer" table="employer">
<key column="employer_id"/>
<property name="companyCarBrand" column="company_car_brand"/>
<set name="subordinates" >
<key column="supervisor_id" not-null="true" />
<one-to-many class="com.javalobby.tnt.domain2.Employee"/>
</set>
</joined-subclass>
</joined-subclass>
</class>
</hibernate-mapping>

_________________
Jack


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.