I've got the same problem.
In my case:
Code:
<hibernate-mapping>
<class name="xxx.Client" table="clients">
<id column="id" name="id" type="int">
<generator class="increment"/>
</id>
<property column="email" name="email" type="java.lang.String"/>
<property column="name" name="name" type="java.lang.String"/>
<property column="password" name="password" type="java.lang.String"/>
<one-to-one cascade="all" class="xxx.ClientMainAccount" property-ref="client" name="mainAccount" />
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class discriminator-value="0" name="xxx.Account" table="accounts">
<id column="id" name="id" type="int">
<generator class="increment"/>
</id>
<discriminator column="type_id" type="integer"/>
<property column="currency_id" name="currencyId" type="int"/>
<property column="amount" name="amount" type="double"/>
<subclass discriminator-value="10" name="xxx.ClientMainAccount">
<join table="client_main_accounts">
<key column="account_id"/>
<many-to-one cascade="all" class="xxx.Client" column="client_id" name="client" not-null="true" />
</join>
</subclass>
<subclass discriminator-value="11" name="xxx.ClientAccount">
<join table="client_accounts">
<key column="account_id"/>
<many-to-one cascade="all" class="xxx.Client" column="client_id" name="client" not-null="true" />
</join>
</subclass>
</class>
</hibernate-mapping>
Hibernate generates:
Quote:
select
client0_.id as id4_1_,
client0_.email as email4_1_,
client0_.name as name4_1_,
client0_.password as password4_1_,
clientmain1_.id as id5_0_,
clientmain1_.currency_id as currency3_5_0_,
clientmain1_.amount as amount5_0_,
clientmain1_1_.client_id as client2_6_0_
from
clients client0_
left outer join
accounts clientmain1_
on client0_.id=clientmain1_.client_id
and clientmain1_.type_id=10
left outer join
client_main_accounts clientmain1_1_
on clientmain1_.id=clientmain1_1_.account_id
where
client0_.id=?
Caused by: org.postgresql.util.PSQLException: ERROR: column clientmain1_.client_id does not exist :(
But correct in my case is something like this:
Code:
select
client0_.id as id4_1_,
client0_.email as email4_1_,
client0_.name as name4_1_,
client0_.password as password4_1_,
client0_.registration_date as registra5_4_1_,
t.id as id5_0_,
t.currency_id as currency3_5_0_,
t.amount as amount5_0_,
t.client_id as client2_6_0_
from
clients client0_
left outer join
(
select * from
accounts clientmain1_
left outer join
client_main_accounts clientmain1_1_
on clientmain1_.id=clientmain1_1_.account_id
where clientmain1_.type_id=10
) t
on client0_.id=t.client_id
where
client0_.id=1
I need hibernate to join superclass and subclass before joining with one-to-one