Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Problem Persisting a Map

I would start by trying to explicitly manage the object you are trying to update.

i.e. get it from the map and merge it explicitly into the persistence context. When you do that and make the change, do you see the changes in the database.

-Tom

phil rod wrote:
Thanks for the pointers!
I have a Map of Map and I am trying to update the value of the same key ,
like if I have <ui 8,9> next time I want to have <ui, 8,9,10>
I have specified the Cascade type in MyPref class for PDMap attributes, and for the
Map<String, PD>   mapOfMaps = *new* HashMap<String, PD>(); in PDMap class
however I am not sure how I can specify the cascade Type for the value type <PD> in the mapOfMaps ? And also I am actually doing this in a transaction and is managed and the steps are :
 em.find(myPref)  //myPref is the base object holding the associations
myPref.setAttribute("ui", "recentProjs","8,9"); //basically here I am trying to update the vlaue of the Map for the same key
em.merge(myPref)

On Fri, May 20, 2011 at 11:30 AM, Tom Ware <tom.ware@xxxxxxxxxx <mailto:tom.ware@xxxxxxxxxx>> wrote:

    It's not completely clear to me what you are trying to do but...

    For changes to be detected in an object, it must be managed.  I
    don't see an settings that would cause your merge to be cascaded.
     Try either explicitly merging the objects you want to see changes
    for, or setting the mappings on your graph to cascade their merge.

    -Tom

    phil rod wrote:

        Any suggestions and ideas how to solve this ?
         While posting I missed one the fields for this class:
        class PD {
         long id;
         String name;

        @ManyToOne

        *private* PDMap dMap;

        @Converter

        (name="mapConverter",
        converterClass=StringMapJsonSerializedObjectConverter.*class*)

        @Convert("mapConverter")

        Map<String, Object> map = *new* HashMap<String, Object>();

         }


        On Wed, May 18, 2011 at 8:45 AM, phil rod
        <philrod.phil@xxxxxxxxx <mailto:philrod.phil@xxxxxxxxx>
        <mailto:philrod.phil@xxxxxxxxx <mailto:philrod.phil@xxxxxxxxx>>>
        wrote:

           Hi All,
                I have the following Mappings:
                class MyPref {
                long id;

           @OneToOne

           (cascade=CascadeType./ALL/, fetch=FetchType./EAGER/)

           **PDMap attributes = *new* PDMap();
           }
                class PDMap {
                long id;

           @OneToMany

           (mappedBy="dMap", cascade=CascadeType./ALL/,
        fetch=FetchType./EAGER/)

           @MapKey(name="name")

           Map<String, PD>

           mapOfMaps = *new* HashMap<String, PD>();
           }
                table PD
           class PD {
                long id;

           @ManyToOne

           *private* PDMap dMap;

           @Converter

           (name="mapConverter",
           converterClass=StringMapJsonSerializedObjectConverter.*class*)

           @Convert("mapConverter")

           Map<String, Object> map = *new* HashMap<String, Object>();

                }
                I am trying to do the following .
                first time I insert into the entities using the key "ui"
        for PDMap
           and the key "recentprojs" for the PD's map.
                PDMap looks like this
           id , creationdate, lastupdatedate
           1 , date, date
                table PD looks like this:
           id, name, map dmap_id
           1, "ui", {"recentprojs":"11"}, 1
                next time when I retreive the same row using
                myPref.getAttribute("ui","recentprojs"); i get the right
        row.
                now I am trying to update that entry to something like this:
                myPref.setAttribute("ui","recentprojs", "11,9");
           em.merge(myPref)
                so that PD table look like this:
           id, name, map dmap_id
           1, "ui", {"recentprojs":"11,9"}, 1
                and PDMap updates the respective dates,
                     but since I am updating the value for the same key
        its not detecting
           any changes and no updates happen to the tables... why is this ?
                but when I change the it to something like this :
           userPref.setAttribute("ui_1","recentproj", "11,9"); a new record
           gets inserted in PD table but no update to the dates in PDMap
        table.          but What I want to achieve is update the same
        row with the
           new/updated values, how can I do this , and what is happening
        here..
           Appreciate Any suggestiongs and ideas ?
                Thank you!
                Phil

        ------------------------------------------------------------------------

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

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



------------------------------------------------------------------------

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


Back to the top