|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
how to update entities with persisted entitiesI 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@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
AW: how to update entities with persisted entitiesHi 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@...> schrieb am Sa, 8.11.2008: > Von: Leon Derks <leon.derks@...> > Betreff: [eclipselink-users] how to update entities with persisted entities > An: "EclipseLink User Discussions" <eclipselink-users@...> > 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@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Re: AW: how to update entities with persisted entitiesHi 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@...> schrieb am Sa, 8.11.2008: > > >> Von: Leon Derks <leon.derks@...> >> Betreff: [eclipselink-users] how to update entities with persisted entities >> An: "EclipseLink User Discussions" <eclipselink-users@...> >> 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@... > 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 > > > > _______________________________________________ eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Re: AW: how to update entities with persisted entitiesHello Leon
It is not clear what you expect to happen to the list importGroups. In your attached code you are not updating the list and you are not updating the instance that is in the list. Perhaps you could explain in detail what you want to happen and why the supplied code should be working? This will help pinpoint where the issue is. --Gordon Leon Derks wrote: > 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@...> schrieb am Sa, 8.11.2008: >> >> >>> Von: Leon Derks <leon.derks@...> >>> Betreff: [eclipselink-users] how to update entities with persisted >>> entities >>> An: "EclipseLink User Discussions" <eclipselink-users@...> >>> 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@... >> 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 >> >> >> >> > > _______________________________________________ > eclipselink-users mailing list > eclipselink-users@... > https://dev.eclipse.org/mailman/listinfo/eclipselink-users _______________________________________________ eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Re: how to update entities with persisted entitiesHello 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@... > https://dev.eclipse.org/mailman/listinfo/eclipselink-users eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Re: how to update entities with persisted entitiesI want the groups in my importData.getCharacterisicGroups() to be
updated with the persisted id, or the newly assigned id. What I am seeing now, that only for new persited groups, the id is automatically updated (viewing importData.getCharacterisicGroups() in debugger perspective). But for groups that are already in de db (and had a result for characteristicGroupDAO.findGroupByExample(importGroup) ), the id is not updated and it stays 0. For this I do nothing extra. How is this possible, that the id is only updated for newly persisted groups. What I want is each group in importData.getCharacterisicGroups() to automatically be updated with the persisted group. Leon christopher delahunt wrote: > 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@... >> https://dev.eclipse.org/mailman/listinfo/eclipselink-users > _______________________________________________ > eclipselink-users mailing list > eclipselink-users@... > https://dev.eclipse.org/mailman/listinfo/eclipselink-users > > > __________ NOD32 3599 (20081110) Informatie __________ > > Dit bericht is gecontroleerd door het NOD32 Antivirus Systeem. > http://www.nod32.nl > > > _______________________________________________ eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Re: how to update entities with persisted entitiesI'm guessing you want to be doing something like this:
//Loop through the groups List<CharacteristicGroup> importGroups = importData.getCharacterisicGroups(); for(int index = 0; index < importGroups.size(); index++) { CharacteristicGroup importGroup = importGroups.get(index); importGroup = updateWithPersistedCharacteristicGroup(importGroup); importGroups.set(index, importGroup); }
James Sutherland EclipseLink, TopLink Wiki: EclipseLink, TopLink Forums: TopLink, EclipseLink Book: Java Persistence |
| Free embeddable forum powered by Nabble | Forum Help |