OriginalPostID-80520
Discussion posts and replies are publicly visible
The comment from sayalip helped me in my case. For some reason the "@GeneratedValue" wasn't added to the primary key field in the XSD by Appian, so I added this manually and the error was resolved.
Thank you ! It helped me.
I got this same error. (Details: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save())
I had wanted to create my first Appian WEB API.
I created a Data Store Entity without an autogenerated ID field.
I created a Service Account and got an API key, put the Service account into the viewer group and gave it access to my DSE, per the docs (Creating Web APIs - Appian 21.3)
My primary key(PK) field is unique, and called CNUMBER.
I tried to use the first example example in the
a!writeToDataStoreEntity( dataStoreEntity: cons!CES_POINTER_CHECKS_DATASTOREENTITY, valueToStore: type!Employee( CNUMBER: http!request.queryParameters.CNUMBER, CDATE: http!request.queryParameters.CDATE, CAMOUNT: http!request.queryParameters.CAMOUNT, CDESC: http!request.queryParameters.CDESC ), onSuccess: a!httpResponse( statusCode: 200, headers: { a!httpHeader(name: "Content-Type", value: "application/json") }, body: a!toJson( fv!storedValues ) ), onError: a!httpResponse( statusCode: 500, headers: { a!httpHeader(name: "Content-Type", value: "application/json") }, body: a!toJson( { error: "There was an error writing to the data store" } ) ) )
When I tested it in the WEB API node it worked perfectly and added or updated a record in my table.
When I tried to access remotely, I got the error.
I tried adding an auto generated id field, then the WEB API node failed and I still got the error. I would up fixing this by using the Web API Tutorial Level II example: Web API Tutorial - Level II - Appian 21.3
So the working code is:
a!localVariables( local!value: cast( 'type!{urn:com:appian:types}CES_CHECKS', a!fromJson(http!request.body) ), a!writeToDataStoreEntity( dataStoreEntity: cons!CES_POINTER_CHECKS_DATASTOREENTITY, valueToStore: local!value, onSuccess: a!httpResponse( statusCode: 200, headers: { a!httpHeader( name: "Content-Type", value: "application/json" ) }, body: a!toJson(fv!storedValues) ), onError: a!httpResponse( statusCode: 500, headers: { a!httpHeader( name: "Content-Type", value: "application/json" ) }, body: a!toJson( { error: "There was another error writing to the data store" } ) ) )
)
Which works great when called from UBUNTU curl as follows:
curl myenv.appian.community/.../myenv_cendpoint -H "Appian-API-Key:MySecretApiKeykjldsjfksjflsjdfsjldsjfkldjslfj" -H "Content-Type:application/json" --request POST --data '{"CNUMBER":12,"CDATE":"20210920","CAMOUNT":2123.44,"CDESC":"a desc"}'
This was a pain to hack out. Hope this helps someone!
Thanks this help!