I'm trying to use @SecondaryTable, hoping to join from a foreign key on my p

I'm trying to use @SecondaryTable, hoping to join from a foreign key on my primary table to the primary key on the secondary table. However it seems to ignore my referencedColumn annotation and joins to the primary key of my primary table. Is it not possible to use @SecondaryTable with something other than the primary key of the primary table?

DOC_TABLE:
DOC_ID (pk)
TYPE_ID (fk to LOOKUP_ID of LOOKUP table)

LOOKUP_TABLE:
LOOKUP_ID (pk)
DOMAIN_VALUE (field I want to show in my CDT).

CDT mapping:
<xsd:complexType name="TAX_Doc">
<xsd:annotation>
<xsd:appinfo source="appian.jpa">
@Table(name="DOC_TABLE")
@SecondaryTable(name="LOOKUP_TABLE", pkJoinColumns=@PrimaryKeyJoinColumn(name="LOOKUP_ID", referencedColumnName="TYPE_ID"))
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="id" type="xsd:int">
<xsd:annotation>
<xsd:appinfo source="appian.jpa">
@Column(name="DOC_ID", nullable=false)
...

OriginalPostID-81009

OriginalPostID-81009

  Discussion posts and replies are publicly visible

Parents
  • I'll just add a clarification here for anyone who searches SecondaryTable and finds this post.

    SecondaryTable is meant exclusively to join 2 tables where the secondary table has a column that matches the primary table's primary key column. The purpose is to be able to split tables with a large amount of columns into several tables, and then have them seamlessly join with SecondaryTable to make it look as if it is one big table with all the columns. It is not meant to join lookup or reference tables that map against specific non-primary key columns. That is why SecondaryTable doesn't have a parameter to configure which column to use from the primary table. It will only map against the primary key of the primary table.

    For mapping lookup or reference data, you have to do a regular nested CDT even if it just has 2 fields (e.g. lookupId, lookupValue). That being said, the best practice is not to do nested CDTs for lookup data. It's better to just manage the lookup ID in the main CDT, and then use constants to get the lookup display value whenever there's a need to see the display value and not the lookup ID.

    For displaying in a paging grid, helper CDTs might be necessary along with the updatearray function to switch the lookup ID with the display value.

    As a final note, here's the JPA reference definition for SecondaryTable:
    "The SecondaryTable annotation is used to specify a secondary table for the annotated entity class. Specifying one or more secondary tables indicates that the data for the entity class is stored across multiple tables."
Reply
  • I'll just add a clarification here for anyone who searches SecondaryTable and finds this post.

    SecondaryTable is meant exclusively to join 2 tables where the secondary table has a column that matches the primary table's primary key column. The purpose is to be able to split tables with a large amount of columns into several tables, and then have them seamlessly join with SecondaryTable to make it look as if it is one big table with all the columns. It is not meant to join lookup or reference tables that map against specific non-primary key columns. That is why SecondaryTable doesn't have a parameter to configure which column to use from the primary table. It will only map against the primary key of the primary table.

    For mapping lookup or reference data, you have to do a regular nested CDT even if it just has 2 fields (e.g. lookupId, lookupValue). That being said, the best practice is not to do nested CDTs for lookup data. It's better to just manage the lookup ID in the main CDT, and then use constants to get the lookup display value whenever there's a need to see the display value and not the lookup ID.

    For displaying in a paging grid, helper CDTs might be necessary along with the updatearray function to switch the lookup ID with the display value.

    As a final note, here's the JPA reference definition for SecondaryTable:
    "The SecondaryTable annotation is used to specify a secondary table for the annotated entity class. Specifying one or more secondary tables indicates that the data for the entity class is stored across multiple tables."
Children
No Data