Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Object hierarchy create not persisting due to null parent key
Object hierarchy create not persisting due to null parent key [message #546718] Tue, 13 July 2010 22:30 Go to next message
Fericit Bostan is currently offline Fericit BostanFriend
Messages: 68
Registered: June 2010
Member

I'm using EclipseLink 2.0 with GlassFish 3.0.1 and Spring 3.0. I'm using the Spring jpaTemplate to execute my operations, GlassFish is managing my transactions and I'm running against MSSQL.

I'm invoking my create method from a WebService. The client is providing the call with an object hierarchy based upon values retrieved from the database. When the create method is invoked on the WebService I perform lookups for the objects that are currently persisted, to ensure that I have the current reference and I assign them to the inbound object.

Everything seems to operate successfully until the transaction commits. Then I get an exception pertaining to a null parent key. The relationships are as follows:

AnswerSet
- contains Answers
- Answer has Selections
- Answer has AnswerText

EclipseLink doesn't seem to be persisting these objects in the correct order. It appears to be persisting the answer first rather than the AnswerSet. Below is the trace:

FINER: client acquired
FINER: TX binding to tx mgr, status=STATUS_ACTIVE
FINEST: PERSIST operation called on: com.soma.persistence.entity.AnswerSet[answersetid=null].
FINEST: PERSIST operation called on: com.soma.persistence.entity.Answer[answerid=null].
FINEST: PERSIST operation called on: com.soma.persistence.entity.Selection[selectionid=null].
FINEST: PERSIST operation called on: com.soma.persistence.entity.Answer[answerid=null].
FINEST: PERSIST operation called on: com.soma.persistence.entity.Selection[selectionid=null].
FINEST: PERSIST operation called on: com.soma.persistence.entity.Answer[answerid=null].
FINEST: PERSIST operation called on: com.soma.persistence.entity.AnswerText[answertextid=null].
FINEST: PERSIST operation called on: com.soma.persistence.entity.Answer[answerid=null].
FINEST: PERSIST operation called on: com.soma.persistence.entity.AnswerText[answertextid=null].
FINEST: PERSIST operation called on: com.soma.persistence.entity.Answer[answerid=null].
FINEST: PERSIST operation called on: com.soma.persistence.entity.Selection[selectionid=null].
FINEST: PERSIST operation called on: com.soma.persistence.entity.Answer[answerid=null].
FINEST: PERSIST operation called on: com.soma.persistence.entity.AnswerText[answertextid=null].
FINER: TX beforeCompletion callback, status=STATUS_ACTIVE
FINER: begin unit of work commit
FINER: TX beforeCompletion callback, status=STATUS_ACTIVE
FINER: begin unit of work commit
FINEST: PERSIST operation called on: com.soma.persistence.entity.Answer[answerid=null].
FINEST: PERSIST operation called on: com.soma.persistence.entity.Selection[selectionid=null].
FINEST: Execute query DoesExistQuery(referenceClass=Choice )
FINER: TX beginTransaction, status=STATUS_ACTIVE
FINEST: Execute query UpdateObjectQuery(com.soma.persistence.entity.Question[questionid=1])
FINEST: reconnecting to external connection pool
FINE: UPDATE Question SET WhenModified = ?, Version = ? WHERE ((QuestionId = ?) AND (Version = ?))
	bind => [2010-07-13 15:18:58.481, 4, 1, 3]
FINEST: Execute query InsertObjectQuery(com.soma.persistence.entity.Answer[answerid=null])
FINE: INSERT IGNORE INTO Answer (UUID, Version, AnswerSetId, QuestionId, ModifiedById, WhenCreated, WhenModified) VALUES (?, ?, ?, ?, ?, ?, ?)
	bind => [72bc5926-0f11-4b35-9d39-008c47b52a32, 1, null, 1, , 2010-07-13 15:18:58.48, 2010-07-13 15:18:58.48]
FINE: SELECT 1
WARNING: Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert the value NULL into column 'AnswerSetId', table 'dev.dbo.Answer'; column does not allow nulls. INSERT fails.
Error Code: 515
Call: INSERT IGNORE INTO Answer (UUID, Version, AnswerSetId, QuestionId, ModifiedById, WhenCreated, WhenModified) VALUES (?, ?, ?, ?, ?, ?, ?)
	bind => [72bc5926-0f11-4b35-9d39-008c47b52a32, 1, null, 1, , 2010-07-13 15:18:58.48, 2010-07-13 15:18:58.48]
Query: InsertObjectQuery(com.soma.persistence.entity.Answer[answerid=null])


How can I tell EclipseLink to persist the AnswerSet before all other objects?

Thanks for the help...

[Updated on: Wed, 14 July 2010 13:13]

Report message to a moderator

Re: Object hierarchy create not persisting due to null parent key [message #546864 is a reply to message #546718] Wed, 14 July 2010 13:14 Go to previous message
Fericit Bostan is currently offline Fericit BostanFriend
Messages: 68
Registered: June 2010
Member
I found it. The parent object was not getting set on the child objects, which prevented it from being persisted first.
Previous Topic:Rollback in transaction causes BlazeDS 3.x to invoke ClassDescriptor.getInheritancePolicy()
Next Topic:org.eclipse.persistence.exceptions.ValidationException
Goto Forum:
  


Current Time: Tue Apr 16 13:55:54 GMT 2024

Powered by FUDForum. Page generated in 0.19146 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top