|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Data updated during aboutToInsert isnt getting persistedI 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? |
|
|
Re: Data updated during aboutToInsert isnt getting persistedJust 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.
|
|
|
Re: Data updated during aboutToInsert isnt getting persistedAt 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.
James Sutherland EclipseLink, TopLink Wiki: EclipseLink, TopLink Forums: TopLink, EclipseLink Book: Java Persistence |
|
|
Re: Data updated during aboutToInsert isnt getting persistedI 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
|
|
|
Re: Data updated during aboutToInsert isnt getting persistedTry 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.
James Sutherland EclipseLink, TopLink Wiki: EclipseLink, TopLink Forums: TopLink, EclipseLink Book: Java Persistence |
| Free embeddable forum powered by Nabble | Forum Help |