CDT Write to Data Store error: primary key "doesn't have a default value"

I created a CDT mapped to a data store entity with an auto-generated primary key (field name = "id").  I have a process that inserts one new instance of the CDT each time it runs.  The first two executions created two entries in the data store as expected.  The third and subsequent tries failed to insert, and produced this error message:

Details:  An error occurred while trying to write to the entity “CB_PWDBW” [id=b20cef01-aa95-4382-84eb-14de73b1a967@4057, type=CB_PWDBW (id=2778)] (data store: CB Data Store). Details: org.hibernate.exception.GenericJDBCException: could not insert: [CBPWDBWDT1716]: java.sql.SQLException: Field 'id' doesn't have a default value Data: TypedValue[it=2778,v={Bainwright Corporation,9998887776665,1,1,0,0,1,{,Chicago,IL,,USA,},<null>}]

I'm puzzled by this error, as the field"id" is defined as a primary key, with the auto-generate option checked:

Any help would be appreciated.

  Discussion posts and replies are publicly visible

  • +1
    Certified Lead Developer

    Hi  may I know, which database you are working with. If you are working with Oracle, then you shouldn't use id and name as a column name, because these are the reserved keywords of Oracle. But if you are working with MySQL then I believe, Cross check the following use cases as mention below:

    Case 1: Check the table structure in DB explicitly and make sure Id is configured as AUTO_INCREMENT because your mapping can be successful in Appian even when AUTO_INCREMENT configuration do not match.

    Case 2: create a duplicate CDT and modify the xsd (entity name, column name etc) and persist the data on this entity.

    As per my understanding, Case 1 might be useful.

  • Hi petef,

    Can you please tel me after inserting 2 entries in your table then you are updated the cdt again by selected auto generated check box

    if yes, please create new version of cdt.

    if no, no need to pass any value to the primary and auto generate column, it will update automatically.

    Hope it will help you

    Regards,
    Bhanu.
  • I'm not sure which DB it is--it's the one that comes with Appian. The data source is java:/jdbc/Appian, is that SQL or Oracle (or can it still be either)?
  • Bhanu, I enabled the auto-generated primary key when I first created the CDT. I am also NOT assigning anything into the primary key field before the Write to Data Store Entity step.

    Also, just in case the DB is Oracle, I changed the primary key name from "id" to "partyId", saved that, confirmed the data store is using the updated CDT. Even so, trying to add new entries is failing, giving the same error as before.
  • Hi petef,

    how did you configured the id column in your CDT?

    check the table structure in database whether the id column is primary key or not.

    if everything looks fine then drop the table and create again by save and publishing the data store.
  • Bhanu, Venkat, all--thanks for the pointers. I figured out what the problem was. The revelation to me was that I could use the Runtime Data engine to view and even modify all of the tables in my database. Once I had that visibility into what my CDTs were becoming in the (SQL) database, it was clear what I needed to fix. I had created some nested CDTs with the wrong type of foreign key relationships. When you have nested CDTs simply to encapsulate details, such as an address CDT that is within a customer CDT, it should be set up with a One-To-One relationship, and only the "Updates to a parent value should also update the associated child values" box checked.