[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Data updated during aboutToInsert isnt getting persisted
|
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.
>
>
>
> khaskett wrote:
>>
>> Just an update to this post..
>> This is the code that is running just prior to the insert.
>>
>> public void aboutToInsert(DescriptorEvent event) {
>> CpBuildingInterestLink bil = (CpBuildingInterestLink)
>> event.getObject();
>> if (bil.getInterestLinkId() == null) {
>> bil.setInterestLinkId(new
>> CpInterestLinkId(getCpInterestType().getInterestTypeId(),
>> cpBuilding.getBuildingId()));
>> }
>> }
>>
>> I notice that both the entity that represents "this" object, and what I
>> get from event.getObject are one in the same. Initially I had thought
>> they were different.
>>
>>
>> khaskett wrote:
>>>
>>> I added the DescriptorEventListener to one of my Entities, and then in
>>> the aboutToInsert method, I added some code to update the EmbedddId
>>> field entry to the value of one the parent entities autogenerated id's.
>>> When I step through the code it stops just prior to that entity getting
>>> inserted, as I can see the parent entity getting inserted, and I can see
>>> the code execute in the aboutToInsert adding the appropriate values, but
>>> when it actually runs the insert it still has null as the value in the
>>> fields I had updated.
>>>
>>> Any ideas on why this is happening?
>>>
>>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Data-updated-during-aboutToInsert-isnt-getting-persisted-tp25928146p26026871.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.