Problem:
I'm trying to use JPA annotations to reflect a http://docs.jboss.org/hibernate/orm/4.0/manual/en-US/html_single/#inheritance-tablepersubclass case. When coding this in the hibernate xml format this works. When using JPA annotations the generated sql needs a discriminator column. I guess I'm mapping something wrong but according to http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#d0e1168 (
2.2.4.3) it should work.
Versions:
JPA 2, Hibernate 4.0.1 and DB2 9.7 dialect.
DB model:
PRINT has a 1:1 relationship with PRODUCTION, PRINT_ID = PRODUCTION_ID.
Domain:
Code:
@Entity
@Table(name = "PRODUCTION")
@Inheritance(strategy = JOINED)
public class Production {
@Column(name = "PRODUCTION_ID")
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
}
Code:
@Entity
@Table(name = "PRINT")
@PrimaryKeyJoinColumn(name = "PRINT_ID")
public class Print extends Production {
}
Hibernate mapping:
Code:
<class name="Production" table="PRODUCTION">
<id name="id" type="java.lang.Long" access="field">
<column name="PRODUCTION_ID" />
<generator class="assigned" />
</id>
<joined-subclass name="Print" table="PRINT">
<key column="PRINT_ID"/>
</joined-subclass>
</class>
Hibernate xml generated SQL (correct):
Code:
select
print0_.PRINT_ID as ID4_
from
PRINT print0_
inner join
PRODUCTION print0_1_
on print0_.PRINT_ID=print0_1_.ID
where
print0_.PRINT_ID=? fetch first 2 rows only
JPA generated SQL (wrong):
Code:
select
print0_.PRODUCTION_ID as PRODUCTION2_9_,
from
PRODUCTION print0_
left outer join
PRINT print0_1_
on print0_.PRODUCTION_ID=print0_1_.PRODUCTION_ID
where
print0_.DTYPE='Print'
and print0_.PRODUCTION_ID=? fetch first 2 rows only