Foreign Key Constraint Fails

Hello,

 

I have a user input task, a script task to set data,and a write to data store node that were in a large process model. Everything worked fine and write to the DB fine as well. To make things easier, I decided to put these three nodes in its own subprocess. Copied and pasted everything into the subprocess however, as soon as I ran this new process, I got this error and now the data store write isn't happening. Any idea why?

 An error occurred while trying to write to the entity “USER_INFO” [id=24fe567f-17c1-4a15-9f72-a88f6036ebe7@4344, type=USER_INFO (id=6362)] (data store: App Data). Details: org.hibernate.exception.ConstraintViolationException: could not insert: [USERINFODT6973]: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`Appian`.`USER_INFO`, CONSTRAINT `USER_INFO_fk_1` FOREIGN KEY (`USER_ID`) REFERENCES `CORE_Appian_User` (`USER_ID`)) Data: TypedValue[it=6362,v={<null>,0,,,,,,,,,2018-02-08,,<null>}] 

  Discussion posts and replies are publicly visible

  • HI Ck,

    It seems that you are trying to insert the USER_ID in table 2 (child table) which is not available in parent table that's why you are getting this error.

    Earlier you were inserting row in child table after successful insertion in parent table.

    Regards
    Abhay
  • You have nested CDT which is getting null value for mandatory column. Thanks
  • Hi CK,

    foreign key constraint is null that why you got this error.

    1)when you are saving your parent table ,in write to data store node collect that data from output of that node.

    2)you said you have taken a sub process node to save the child table(where parent table id is fk),when you are confirming this sub process ,in input variables pass the parent table which you have collected from write to data store node.

    3)map the parent table id in child table in script task which is in sub process .

  • Hi,

    Foreign key should not be null while writing the data to the database.
    So please verify the value to which foreign key is mapped and check if it is null or not
  • Hi Ck,

    Can you please check your CDT mapping? it should be as shown below for foreign key mapping:

    <xsd:schema xmlns:xsd="www.w3.org/.../XMLSchema" xmlns:tns="urn:com:appian:types:mainTable" targetNamespace="urn:com:appian:types:mainTable">
    <xsd:include schemaLocation="%7Burn%3Acom%3Aappian%3Atypes%3A7DsubTable.xsd" />
    <xsd:complexType name="Main_Table">
    <xsd:annotation>
    <xsd:appinfo source="appian.jpa">
    @Table(name="Main_Table")
    </xsd:appinfo>
    </xsd:annotation>
    <xsd:sequence>
    <xsd:element name="id" nillable="true" type="xsd:int">
    <xsd:annotation>
    <xsd:appinfo source="appian.jpa">@Id @Column(name="ID", columnDefinition="int", nullable=false) @GeneratedValue</xsd:appinfo>
    </xsd:annotation>
    </xsd:element>
    <xsd:element maxOccurs="unbounded" minOccurs="0" name="subTable" type="tns:subTable">
    <xsd:annotation>
    <xsd:appinfo source="appian.jpa">@OneToMany(indexed=false) @JoinColumn(name="mainTableID", nullable=false)</xsd:appinfo>
    </xsd:annotation>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:schema>

    The above mapping will automatically set the main table's id as a foreign key on the sub table to the mapped column(mainTableID).