Hi,

I have a weird case where EOF fails to include the primary key with an INSERT, but not every time. The model of the EO in question looks like this:


The linkKey column is actually new. I discovered that the primary key before was (journeyElementRef,workflow) which lead to other problems I needed to solve, and the database (PostgresQL) didn’t even know any primary key (although there was a unique index). So I fixed that by introducing a new independent primary key (changing the lock columns along with it), using the following migration code (TableName substituted for readability):

ERXMigrationTable table = database.existingTableNamed( TableName.ENTITY_NAME );
ERXMigrationColumn pcol = table.newIntegerColumn( "linkKey", ALLOWS_NULL );
String[] sqls = new String[] {
"CREATE SEQUENCE jewfelink_seq",
"UPDATE TableName SET linkKey = nextval('jewfelink_seq')",
"DROP SEQUENCE jewfelink_seq",
};
for( String sql : sqls ) {
NSLog.out.appendln( "Executing SQL: " + sql );
ERXJDBCUtilities.executeUpdate( database.adaptorChannel(), sql, true );
}

pcol.setAllowsNull( NOT_NULL );

table.setPrimaryKey( pcol );

The generated migration code was:

alter table TableName alter column linkKey set not null
ALTER TABLE TableName ADD CONSTRAINT TableName_pk PRIMARY KEY (linkKey)
CREATE SEQUENCE TableName_seq
CREATE TEMP TABLE EOF_TMP_TABLE AS SELECT SETVAL('TableName_seq', (SELECT MAX(linkKey) FROM TableName))
DROP TABLE EOF_TMP_TABLE
ALTER TABLE TableName ALTER COLUMN linkKey SET DEFAULT nextval( 'TableName_seq' )

Looks correct to me. When I manually construct a new TableName EO in a test routine, the following SQL is generated:

SELECT NEXTVAL('PDCJourneyElementWorkflowElementLink_seq') AS KEY0" withBindings:
INSERT INTO TableName(workflowElementRef, updateDate, linkKey, workflow, journeyElementRef) VALUES (?::int4,
NULL, ?::int4, ?::varchar(24), ?::int4)" withBindings: 1:2(workflowElementRef), 2:173(linkKey),
3:JE_BOOKING(workflow), 4:697860(journeyElementRef)

so there’s the sequence SELECT to get a new primary key value, followed by the actual INSERT. But in real usage in the application, this is all that happens instead:

INSERT INTO TableName(workflowElementRef, updateDate, workflow, journeyElementRef) VALUES (?::int4, ?::timestamp,
?::varchar(24), ?::int4)" withBindings: 1:7(workflowElementRef), 2:2014-02-07 10:39:51(updateDate), 3:JE_BOOKING(workflow),
4:697860(journeyElementRef)

which of course results in

DEBUG NSLog - Commit failed on data source of type class com.webobjects.eoaccess.EODatabaseContext
java.lang.IllegalArgumentException: Attempt to insert null object into an com.webobjects.foundation.NSMutableDictionary.
at com.webobjects.foundation.NSMutableDictionary.setObjectForKey(NSMutableDictionary.java:78)
at com.webobjects.eoaccess.EODatabaseContext.commitChanges(EODatabaseContext.java:6348)
at com.webobjects.eocontrol.EOObjectStoreCoordinator.saveChangesInEditingContext(EOObjectStoreCoordinator.java:386)
at com.webobjects.eocontrol.EOEditingContext.saveChanges(EOEditingContext.java:3192)
at er.extensions.eof.ERXEC._saveChanges(ERXEC.java:1179)
at er.extensions.eof.ERXEC.saveChanges(ERXEC.java:1102)

because the primary key is missing, there wasn’t even the sequence SELECT before the INSERT.

How can this happen? I suspect it has something to do with the primary key having been another column in the past that didn’t have a sequence associated with it. But from the model, it looks correct to me. Is there some information stored ore cached somewhere else about this?

Maik

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to