Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: AW: [eclipselink-users] how to update entities with persisted entities

Hi Mark,

Yes I want to throw awaay all the changes, because the groups don't change.
The problem is that the imported group in the List importGroups is not updated.
Only new persisted groups are updated.

How is this possible?

Leon

Mark Struberg wrote:
Hi Leon!

Is this all the code?

What's confusing me:
   if(persistedGroup != null) {
        importGroup = persistedGroup;
   }
so you really like to throw away all the changes in your importGroup and take the version from the database? (what about merge?)

LieGrü,
strub

--- Leon Derks <leon.derks@xxxxxxxxxx> schrieb am Sa, 8.11.2008:

Von: Leon Derks <leon.derks@xxxxxxxxxx>
Betreff: [eclipselink-users] how to update entities with persisted entities
An: "EclipseLink User Discussions" <eclipselink-users@xxxxxxxxxxx>
Datum: Samstag, 8. November 2008, 19:21
I am seeing a behaviour which I can not explain.

I have a list of groups (imported from an xml file)
Then I loop through these groups and check if they already
exist in de db.
I want them to be updated with the persisted group.

In my debugger perspective I see that ids of new groups are
updated with the newly assigned id.
But the groups that are already in the db are not updated
with the persisted id.

The makePersistent method does a persist if id == 0 or else
the entity is merged.

What I want is that all importGroups are updated with
either the persisted id, or a newly assigned id.
At the moment only new groups are updated with an id.

How is this possible?

See below for code.


//Loop through the groups
List<CharacteristicGroup> importGroups =
importData.getCharacterisicGroups();
for(CharacteristicGroup importGroup : importGroups) {
   importGroup =
updateWithPersistedCharacteristicGroup(importGroup);
}

private CharacteristicGroup
updateWithPersistedCharacteristicGroup(CharacteristicGroup
importGroup) {
   CharacteristicGroup persistedGroup =
characteristicGroupDAO.findGroupByExample(importGroup);
   if(persistedGroup != null) {
        importGroup = persistedGroup;
   }
   characteristicGroupDAO.makePersistent(importGroup);
   return importGroup;
}



_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users



__________ NOD32 3597 (20081108) Informatie __________

Dit bericht is gecontroleerd door het NOD32 Antivirus Systeem.
http://www.nod32.nl






Back to the top