Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JPA -- Inheritance with duplicate column names

173391May 7 2007 — edited May 7 2007

Hi,

I have the following problem:

I have two tables. Let's call them BASE_TABLE and CHILD_TABLE. They are mapped through Join Inheritance in Java. In other words:

@Inheritance(strategy=InheritanceType.JOINED)

Let's say, the tables look like:

BASE_TABLE (
    ID NUMBER(18),
    TYPE VARCHAR2(1),
    CODE NUMBER(5))

CHILD_TABLE (
    ID NUMBER(18),
    CODE NUMBER(5),
    NAME VARCHAR2(50))

Here's where the problem lies: I have duplicate column names. In my example, this is the CODE column. When mapping to Java classes, I can have something like:

@Entity
@Table(name="BASE_TABLE")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="TYPE", discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue("0")
class BaseEntity {
    .
    .
    .
    @Column(name="CODE")
    private Integer code;

    public Integer getCode_Base() {
        return code;
    }

    public setCode_Base(Integer code) {
        this.code = code;
    }
}


@Entity
@Table(name="CHILD_TABLE")
@DiscriminatorValue("1")
@PrimaryKeyJoinColumn(name="ID")
class ChildEntity extends BaseEntity {
    .
    .
    .
    @Column(name="CODE")
    private Integer code;

    public Integer getCode() {
        return code;
    }

    public setCode(Integer code) {
        this.code = code;
    }
}

The trouble is, that TopLink only handles ONE of the CODE columns. When SELECTing, it only selects the CODE column from table BASE_TABLE. When generating DML statements, again it only uses the CODE column from table BASE_TABLE.

I wasn't able to make it use BOTH columns.

Please, help. The DB design cannot be changed at the moment. However, I must find a way to make TopLink Essentials use both CODE columns, not just the one from BASE_TABLE.

Thank you in advance!

Best regards,
Bisser

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 4 2007
Added on May 7 2007
2 comments
2,422 views