How to specify a different column for a @Inheritance JPA annotation

Posted by Cue on Stack Overflow See other posts from Stack Overflow or by Cue
Published on 2009-08-04T11:44:12Z Indexed on 2010/06/18 14:53 UTC
Read the original article Hit count: 252

Filed under:
|
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class Foo   

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class BarFoo extends Foo

mysql> desc foo;
+---------------+-------------+
| Field         | Type        |
+---------------+-------------+
| id            | int         |
+---------------+-------------+

mysql> desc barfoo;
+---------------+-------------+
| Field         | Type        |
+---------------+-------------+
| id            | int         |
| foo_id        | int         |
| bar_id        | int         |
+---------------+-------------+

mysql> desc bar;
+---------------+-------------+
| Field         | Type        |
+---------------+-------------+
| id            | int         |
+---------------+-------------+

Is it possible to specify column barfo.foo_id as the joined column?

Are you allowed to specify barfoo.id as BarFoo's @Id since you are overriding the getter/seeter of class Foo?

I understand the schematics behind this relationship (or at least I think I do) and I'm ok with them.

The reason I want an explicit id field for BarFoo is exactly because I want to avoid using a joined key (foo _id, bar _id) when querying for BarFoo(s) or when used in a "stronger" constraint. (as Ruben put it)

© Stack Overflow or respective owner

Related posts about java

Related posts about jpa