-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping problem with JPA + inheritance (works with xml)
PostPosted: Tue Sep 25, 2012 4:38 am 
Newbie

Joined: Wed May 05, 2004 1:00 pm
Posts: 7
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.