Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Data updated during aboutToInsert isnt getting persisted

Try just using record.put("INTEREST_TYPE_ID", cpBuilding.getBuildingId()),
the entry stuff may not be changing the record.

There is also a method on event to update the row and change-set,
updateAttributeWithObject(), give it the attribute name and the new value,
it will update the object, row, and change-set.



khaskett wrote:
> 
> I changed the code in abouttoInsert to update the Record so it looks like
> this - 
>         Record record = event.getRecord();
>         Set<AbstractRecord.Entry> entrySet = record.entrySet();
>         for (AbstractRecord.Entry entry : entrySet) {
>            DatabaseField field = (DatabaseField) entry.getKey();
>            if ("INTEREST_TYPE_ID".equals(field.getName())) {
>                entry.setValue(getCpInterestType().getInterestTypeId());
>            } else if ("PARENT_ID".equals(field.getName())) {
>                entry.setValue(cpBuilding.getBuildingId());
>            }
>         }
> I also verified that the correct values were getting inserted.
> 
> Unfortunately it still does not pick up these changes.  Anything else I
> should be doing?
> 
> Here's the error in the console -
> Internal Exception: java.sql.SQLException: [SQL0407] Null values not
> allowed in column or variable INTER00001.
> Error Code: -407
> Call: INSERT INTO CP_INTEREST_LINK (ACTION_CODE, INTEREST_TYPE_ID,
> LINK_TYPE, PARENT_ID) VALUES (?, ?, ?, ?)
> 	bind => [null, null, B, null]
> 
> Thanks
> 
> 
> James Sutherland wrote:
>> 
>> At the point of the aboutToInsert event the row to insert has already
>> been built.  To effect the insert, you need to modify the row
>> (event.getRecord()).  The preInsert event is raised before the row is
>> built, so you could change the object in preInsert.
>> 
>> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/Data-updated-during-aboutToInsert-isnt-getting-persisted-tp25928146p26077804.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top