Multiple SQL commands for a single insert

Certified Associate Developer

Hello there,

I have a parent child relationship mapped within Appian.  When I call writeToDataStore on the parent object, Appian successfully saves both the parent and child objects however it requires 2 SQL commands to save the children.  Specifically what it does is:

  1. INSERT the Parent and Child objects 
  2. UPDATE the child objects with the foreign key of the parent

 

Is there any way to force Appian to insert the Parent and children without requiring the second update command?  IE: Insert the parent, set the FK value on the child, insert the child objects?

Some Hibernate documentation I've read suggests setting up a "ManyToOne" relationship on the child towards the parent however this causes several unusual datastore validation errors (data store does not have a definition for parent or child)

docs.jboss.org/.../example-parentchild.html

 

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer
    Hi as per my understanding, the stored procedure may serve your requirement.

    Also when you talk about Hibernate, JPA or any other Framework/API, when more than one entities are in a relationship, multiple SQL queries will be executed into the DB behind the screen to perform some operation over them.

    e.g. While performing Insert operation, until we do not save the Parent, we don't know the PK value of the Parent row through which the Child Table is linked to.
Reply
  • 0
    Certified Lead Developer
    Hi as per my understanding, the stored procedure may serve your requirement.

    Also when you talk about Hibernate, JPA or any other Framework/API, when more than one entities are in a relationship, multiple SQL queries will be executed into the DB behind the screen to perform some operation over them.

    e.g. While performing Insert operation, until we do not save the Parent, we don't know the PK value of the Parent row through which the Child Table is linked to.
Children
  • 0
    Certified Associate Developer
    in reply to aloks0189
    Hi Aloks,

    It's not true that multiple SQL statements must be run to insert the child objects. It could very well work like this:
    1) Insert Parent object
    2) Read Parent Primary Key
    3) Insert Child Objects

    This is what the documentation I linked in my original post was describing and it's what I'm trying to replicate with Appian's CDT/JPA.

    I would like to avoid a stored procedure if possible because this functionality is provided out of box by Hibernate and a stored proc would require constant secondary updating for every change.