Posted: 27 Apr 2016 17:04 EDT Last activity: 4 Oct 2018 13:54 EDT
Cannot save class instance without a primary key
I have a file listener in my application that would look after csv files.The csv file needs to be parsed and the data for each record has to be saved in an external table in Pega. I have created a class in Pega with no keys as there is no unique attribute for each record I get in the file. When I am trying to save the data in the table, I am getting below error.
Cannot open or save instances of class XXXX--the class might be abstract, or it might have no defined keys, or it might descend from Code-.
Is it required to have a key defined for the class ?
**Moderation Team has archived post**
This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.
Take a look that OOTB example "updateOrder" Connect-SQL rule.
While looking at the rule, do: Actions -> Get Help
Then read the content in the "About" and "Save" tabs.
You should be able to Obj-Save to an external table despite the table not having pzInsKey and pxObjClass columns.
But you said "external table in Pega" which does not makes sense.
You need a separate JDBC database connection to a separate database before calling a table "external".
Did you create a new "Records -> SysAdmin -> Database" record then create a new "Records -> SysAdmin -> Database Table" record for the class that you want to have mapped to your external table - the Data Table record associated to the external Database?
Did you use the Designer Studio -> Integration -> "Connector and Metadata Wizard" choosing Metadata type = SQL?
I'm facing the same issue when using obj-save to save the records to a table in External database. We have used Designer Studio -> Integration -> "Connector and Metadata Wizard" choosing Metadata type = SQL.
"Cannot open or save instances of class Delta-Int-DD_AL_COVG_TO_BENEFIT--the class might be abstract, or it might have no defined keys, or it might descend from Code-. "
I see all the related rules are created by the wizard and we see the above issue when using OBj-Save.
Posted: 4 years ago
Updated: 4 years ago
Posted: 8 Jun 2016 23:44 EDT Updated: 8 Jun 2016 23:50 EDT
It is recommended to have keys for a class (in turn, DB table). If you aren't sure which columns are unique, just create a property in that class called "UniqueID" or something like that and set it's value to @Default.CreateUniqueID() , add that same column in DB table and add that property as a key in your class rule.
@Default.CreateUniqueID() function creates an unique ID which can be used a key.
I have created a concreate class which belongs to the Classgroup and that has the pyID as a Class key. And our requirement is to change pxobjClass in old workobjects that are in the work table. so I wrote and activity first retrieve all the objects which satisfy with the condition and then through a loop I'm opening each and every object and try to change the pxobjclass of it. ( Here page-change-class) method is not working and I used property-set-special method for that , and the trying to save the WO using obj-save method but it gives and error saying
Cannot save a page with an instance of class (Class Name): it is read-only