Embed on Secondary Table

6 Messages Forum Options Options
Embed this topic
Permalink
atilla
Embed on Secondary Table
Reply Threaded MoreMore options
Print post
Permalink
I have two Tables CUSTOMER and CUSTOMER_EXT (mapped as Secondary)

@Entity@Table(name = "CUSTOMER")
@SecondaryTable(name = "CUSTOMER_EXT", pkJoinColumns = @PrimaryKeyJoinColumn(name = "CUST_ID", referencedColumnName = "CUST_ID"))

I have COLUMNS FROM_DT, TO_DT in CUSTOMER_EXT and I am using a class DateRange which maps those columns.

I am trying to embed this class and persist in the Secondary Table.

//Customer.class embeds DateRange.class
@Embedded
@AttributeOverrides( {
@AttributeOverride(name = "from", column = @Column(name = "FROM_DT", table = "CUSTOMER_EXT")),
@AttributeOverride(name = "to", column = @Column(name = "TO_DT", table = "CUSTOMER_EXT"))} )
private DateRange dr;

When I do this it tries to insert into a column named DATERANGE_CUST_ID in CUSTOMER_EXT which obviously is not there.
Any Clues?
Pinaki Poddar
Re: Embed on Secondary Table
Reply Threaded MoreMore options
Print post
Permalink
Hi,
> I have COLUMNS FROM_DT, TO_DT in CUSTOMER_EXT and I am using a class DateRange which maps
> those columns.

Secondary table CUSTOMER_EXT need to have a join column CUST_ID to refer to primary key column of CUSTOMER.CUST_ID. However, your observation does point to a error in OpenJPA as it generates
a column named DATERANGE_CUST_ID instead of CUST_ID as specified in @SecondaryTable(pkJoinColumns=...).

The problem is logged as JIRA report  OPENJPA-705.

Currently you can perhaps workaround as
@SecondaryTable(name = "CUSTOMER_EXT", pkJoinColumns = @PrimaryKeyJoinColumn(name = "DATERANGE_CUST_ID", referencedColumnName = "CUST_ID"))


[1] https://issues.apache.org/jira/browse/OPENJPA-705
atilla
Re: Embed on Secondary Table
Reply Threaded MoreMore options
Print post
Permalink
The secondary table does have the join column CUST_ID. I only mentioned the extra columns!
The wrong column is actually an additional column. I can see that the insert statement for CUSTOMER_EXT has both CUST_ID and DATERANGE_CUST_ID Cols.
Pinaki Poddar
Re: Embed on Secondary Table
Reply Threaded MoreMore options
Print post
Permalink
Hi,
> The secondary table does have the join column CUST_ID.
Good.

Recent commit 688919 on trunk on OPENJPA-705 has a fix.

Pinaki Poddar
Re: Embed on Secondary Table
Reply Threaded MoreMore options
Print post
Permalink
In reply to this post by atilla
Hi,
  If you can update OpenJPA from trunk and verify whether the fix works for you or not, please let us know.

atilla
Re: Embed on Secondary Table
Reply Threaded MoreMore options
Print post
Permalink
worked like a charm. thank you.

here is my test model:
@Entity
@Table(name = "CUSTOMER")
@DiscriminatorColumn(name = "CUSTOMER_CLASS")
@SecondaryTable(name = "CUSTOMER_EXT", pkJoinColumns = @PrimaryKeyJoinColumn(name = "CUST_ID", referencedColumnName = "CUST_ID"))
@Inheritance(strategy = InheritanceType.JOINED)
public class Customer {
...
@Embedded
@AttributeOverrides( {
@AttributeOverride(name = "from", column = @Column(name = "FROM_DT", table = "CUSTOMER_EXT")),
@AttributeOverride(name = "to", column = @Column(name = "TO_DT", table = "CUSTOMER_EXT")) })
private DateRange dr;
...
}

@Entity
@DiscriminatorValue("ORG")
@Table(name="ORGANIZATION")
@PrimaryKeyJoinColumn(name="CUST_ID", referencedColumnName="CUST_ID")
public class Organization extends Customer {...}


Pinaki Poddar wrote:
Hi,
  If you can update OpenJPA from trunk and verify whether the fix works for you or not, please let us know.