Free cookie consent management tool by TermsFeed Replace Deprecated JPA Annotations in CDTs
Replace Deprecated JPA Annotations in CDTs

Overview

Tip:   This page applies to self-managed installations only. Appian Cloud customers do not need to follow these instructions when upgrading to newer versions of Appian.

The 22.4 release includes an update to the Hibernate object-relational mapping library that requires replacement of specific JPA annotations that are no longer supported: @TableGenerator, @PrimaryKeyJoinColumn, @DiscriminatorColumn, and @DiscriminatorValue. The instructions on this page cover replacement of the deprecated annotations with supported ones. You should search your environments for occurrences of these annotations using the instructions on the Upgrade Guide page.

Changing @TableGenerator annotations

CDTs with the @TableGenerator annotation require changes to both the XML Schema definition (XSD file) of the CDT and the SQL definition of the corresponding table. Use these steps to make the changes:

  1. Download the XSD of the relevant CDT.
  2. Remove the @TableGenerator annotation entirely and remove any other references to the table generator. Example:

    Original XSD:

    1
    2
    3
    4
    5
    
     <xsd:appinfo source="appian.jpa">
     @Id
     @TableGenerator(name="example_entity", allocationsSize=10, initialValue=100, table="example_entity_table")
     @GeneratedValue(strategy="TABLE", generator="example_entity")
     </xsd:appinfo>
    

    Modified XSD:

    1
    2
    3
    4
    
     <xsd:appinfo source="appian.jpa">
     @Id
     @GeneratedValue
     </xsd:appinfo>
    
  3. Save the XSD.
  4. From the gear menu inside the CDT designer, select ‘Create New Version from XSD’ and upload the modified XSD.
  5. Get the definition of the table the CDT corresponds to. (See Retrieve a CDT's corresponding table definition below)
  6. Modify the primary key of the table from step #5 to be AUTO_INCREMENT. Example for an integer primary key in MySQL/MariaDB:

    1
    
     ALTER TABLE <tableName> MODIFY <primaryKey> INT NOT NULL AUTO_INCREMENT;
    
  7. Republish the data store using the CDT. It should verify automatically.

Changing @PrimaryKeyJoinColumn annotations

@PrimaryKeyJoinColumn can be a table/entity-level annotation or a column-level annotation. Only column-level occurrences need to be changed. A column-level annotation is preceeded in the logs by the keyword "annotations" instead of the keyword "rawClassAnnotations" used for table/entity-level annotations.

Example table/entity-level annotation that does not need to be changed (notes the "rawClassAnnotations" keyword):

1
{"captureId":"hcuguz","name":"ETB_ECMPositionLite","rawClassAnnotations":" @Table(name\u003d\"ecmposition\") @PrimaryKeyJoinColumn(name\u003d\"ecmposition_position_id\")

Example column-level annotation that does need to be changed (note the "annotations" keyword):

1
(Array)","annotations":"@OneToMany(cascade\u003dCascadeType.ALL, indexed\u003dfalse) @PrimaryKeyJoinColumn(name\u003d\"requestid\")"}

CDTs with the @PrimaryKeyJoinColumn annotation require that you change the XML Schema definition (XSD file) of the CDT. Use these steps to make the change:

  1. Download the XSD of the relevant CDT.
  2. Get the definition of the corresponding table. (See Retrieve a CDT's corresponding table definition below)
  3. Identify the element(s) of the XSD that use @PrimaryKeyJoinColumn and make note of their column name(s) in the table. They should be foreign keys to other tables.
  4. Change @PrimaryKeyJoinColumn to @JoinColumn and specify the name to be the column name from step #3.

    Consider the following example with 2 related CDTs, order and customer:

    Original XSD with 2 CDTs:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    
     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:com:appian:types:A" targetNamespace="urn:com:appian:types:A">
       <xsd:complexType name="order">
         <xsd:sequence>
           <xsd:element name="orderid" nillable="true" type="xsd:int">
             <xsd:annotation>
               <xsd:appinfo source="appian.jpa">@Id</xsd:appinfo>
             </xsd:annotation>
           </xsd:element>
           <xsd:element name="part" nillable="true" type="xsd:string">
             <xsd:annotation>
               <xsd:appinfo source="appian.jpa">@Column(length=255)</xsd:appinfo>
             </xsd:annotation>
           </xsd:element>
           <xsd:element name="customer" nillable="false" type="tns:customer">
             <xsd:annotation>
               <xsd:appinfo source="appian.jpa">@PrimaryKeyJoinColumn(name="customer", referencedColumnName="customerid")</xsd:appinfo>
             </xsd:annotation>
           </xsd:element>
         </xsd:sequence>
       </xsd:complexType>
          
       <xsd:complexType name="customer">
         <xsd:sequence>
           <xsd:element name="customerid" nillable="true" type="xsd:int">
             <xsd:annotation>
               <xsd:appinfo source="appian.jpa">@Id</xsd:appinfo>
             </xsd:annotation>
           </xsd:element>
           <xsd:element name="address" nillable="true" type="xsd:string">
             <xsd:annotation>
               <xsd:appinfo source="appian.jpa">@Column(length=255)</xsd:appinfo>
             </xsd:annotation>
           </xsd:element>
         </xsd:sequence>
       </xsd:complexType>
     </xsd:schema>
    

    Generated table defintion for customer:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
     CREATE TABLE `order` (
       `orderid` int(11) NOT NULL,
       `part` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
       `customer` int(11) NOT NULL,
       PRIMARY KEY (`orderid`),
       UNIQUE KEY `customer` (`customer`),
       KEY `order_customer` (`customer`),
       CONSTRAINT `order_customer` FOREIGN KEY (`customer`) REFERENCES `customer` (`customerid`)
     )
    

    The remediation is to change:

    1
    
     @PrimaryKeyJoinColumn(name="customer", referencedColumnName="customerid")
    

    to

    1
    
     @JoinColumn(name="customer")
    
  5. Save the XSD.
  6. From the gear menu inside the CDT designer, select ‘Create New Version from XSD’ and upload the modified XSD.
  7. Republish the data store using the CDT. It should verify automatically.

Changing @DiscriminatorColumn and @DiscriminatorValue annotations

The updated Hibernate library no longer requires the @DiscriminatorColumn and @DiscriminatorValue annotations, as it now uses internal logic to determine which subclass to query. You need to remove all @DiscriminatorColumn and @DiscriminatorValue annotations from the XML Schema definition (XSD file) of the CDT. Use these steps to make the change:

  1. Download the XSD of the relevant CDT.
  2. Remove the @DiscriminatorColumn annotation from the superclass. For example:

    Original XSD of the superclass:

    1
    2
    3
    4
    5
    6
    
     <xsd:appinfo source="appian.jpa">
     @Entity
     @Table(name="Order")
     @Inheritance(strategy = InheritanceType.JOINED)
     @DiscriminatorColumn(name="OrderTypeCode")
     </xsd:appinfo>
    

    Modified XSD of the superclass:

    1
    2
    3
    4
    5
    
     <xsd:appinfo source="appian.jpa">
     @Entity
     @Table(name="Order")
     @Inheritance(strategy = InheritanceType.JOINED)
     </xsd:appinfo>
    
  3. Remove the @DiscriminatorValue annotation from the subclass. For example:

    Original XSD of the subclass:

    1
    2
    3
    4
    5
    
     <xsd:appinfo source="appian.jpa">
     @Entity
     @DiscriminatorValue(value="2")
     @Table(name="InternalOrder")
     </xsd:appinfo>
    

    Modified XSD of the subclass:

    1
    2
    3
    4
    
     <xsd:appinfo source="appian.jpa">
     @Entity
     @Table(name="InternalOrder")
     </xsd:appinfo>
    
  4. Save the XSD.
  5. In the CDT, click the settings menu > Create New Version from XSD.
  6. Upload the modified XSD.
  7. Click CREATE NEW VERSION.

Retrieve a CDT's corresponding table definition

The name of the table that corresponds to a CDT can be determined by reviewing the CDT's XSD file. If the file includes the @Table annotation, the table’s name is the name specified in the @Table annotation. Otherwise, the table’s name is the lowercase name of the CDT.

To get the table definition:

  1. Find the data store using the CDT
  2. Find the data source of the data store
  3. From the data source find the relevant connection information: host, port, and schema
  4. Connect to the database and retrieve the table definition with

    1
    
     SHOW CREATE TABLE <SCHEMA>.<TABLE>;
    

Replace Deprecated JPA Annotations in CDTs

FEEDBACK