[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] how to update entities with persisted entities
|
Hello Leon,
I'm not sure I understand correctly. I'm guessing that ImportGroup, if
existing, is detached and contains changes that you want persisted. I
assume that findGroupByExample(importGroup) is just a simple query or
find method that returns the managed instance of importGroup. The
problem then would be that you pass this managed copy into the
makePersistent. Since the managed copy doesn't have the changes, they
are lost. You need to merge the detached copy into the managed copy
using the em.merge at some point.
If this isn't the problem, please give more detail as to what data isn't
being persisted and how you are actually finding and persisting your
entities.
Best Regards,
Chris
Leon Derks wrote:
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