Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
More detailed description at the end.
Hibernate version: 3.2 cr4, August 24, 2006
Mapping documents:
<!-- User.hbm.xml -->
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="timereport.domain.users">
<class abstract="true" name="User" table="USERS" polymorphism="implicit">
<id name="id">
<generator class="sequence" />
</id>
<property name="name" not-null="true" />
<property name="password" not-null="true" />
<property name="contact" />
</class>
</hibernate-mapping>
<!-- Worker.hbm.xml -->
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="timereport.domain.users">
<union-subclass name="Worker" extends="User">
<many-to-one name="employer" column="EMPLOYER_ID" update="false" not-null="true" lazy="false" />
</union-subclass>
</hibernate-mapping>
<!-- Employer.hbm.xml -->
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="timereport.domain.users">
<union-subclass name="Employer" extends="User">
</union-subclass>
</hibernate-mapping>
Name and version of the database you are using: hsqldb 1.8.2
The generated SQL (show_sql=true):select user0_.id as id0_, user0_.name as name0_, user0_.password as password0_, user0_.contact as contact0_, user0_.EMPLOYER_ID as EMPLOYER1_2_, user0_.clazz_ as clazz_ from ( select id, null as EMPLOYER_ID, name, contact, password, 1 as clazz_ from Employer union select id, EMPLOYER_ID, name, contact, password, 2 as clazz_ from Worker ) user0_ where user0_.id=? and user0_.password=?
Hello, I have the following class hierarchy:
abstract class User
common properties, just primitives
class Worker extends User
Employer employer
class Employer extends User
The problem is that if i execute the HSQL query "from User where id = :id and password = :password", with the parameters matching a Worker it returns a Worker object, however, the employer association isn't populated.
This is the result i got after executing the union of the to sub-selects:
(that is basically (select * employer union select * worker), with some padding)
Sorry for the insane formatting on this column, don't know how to make it look right :-/
ID EMP_ID NAME CONTACT PASSWD CLAZZ
1 [null] TL Systems . . . . .. . .. . tl 1
14 [null] ICA [null] ica 1
17 [null] TL Systems [null] tl 1
22 [null] TL Systems [null] tl 1
29 [null] apa apa 1
47 17 Tommy Lindberg det är ju jag.. tl 2
The first 5 rows match objects of type Employer, and the last one is a Worker. So far so well, however, after the final select on this union, with ID = 47 and passwd = tl, i get this result:
47 [null] Tommy Lindberg det är ju jag.. tl 2
As a result, the Worker.employer = null, ofcourse.
How come EMP_ID (actually EMPLOYER_ID..) is [null] when it should be 17? I did turn of lazy loading on the employer property of Worker after all.
Feel free to ask any questions, if you don't understand my rambling :P
Kind regards,
Tommy