You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Harald Wellmann (JIRA)" <ji...@apache.org> on 2010/09/08 15:31:32 UTC

[jira] Created: (OPENJPA-1784) Map value updates not flushed

Map value updates not flushed
-----------------------------

                 Key: OPENJPA-1784
                 URL: https://issues.apache.org/jira/browse/OPENJPA-1784
             Project: OpenJPA
          Issue Type: Bug
          Components: jdbc
    Affects Versions: 2.0.1
            Reporter: Harald Wellmann


I have an entity with a map element collection where the map value is an Embeddable.

@Embeddable
public class LocalizedString {

    private String language;
    private String string;

    // getters and setters omitted
}

 

@Entity
public class MultilingualString {

    @Id
    private long id;

    @ElementCollection(fetch=FetchType.EAGER)
    private Map<String, LocalizedString> map = new HashMap<String, LocalizedString>();
}


Given a persistent instance m of my entity, I update a member of a given map value and then merge the modified entity:

    EntityManager em = ...;
    em.getTransaction().begin();
    m.getMap().get("en").setString("foo");
    em.merge(m)
    em.getTransaction().commit();
   
The problem is, the state change of the map does not get saved to the database. With DEBUG logging on, I can see that the flush on commit does not trigger any SQL UPDATE.

To force the update, I have to put a new value into the map instead of just changing the existing one.

    EntityManager em = ...;
    em.getTransaction().begin();
    m.getMap().put("en"), new LocalizedString("en", "foo"));
    em.merge(m)
    em.getTransaction().commit();

After this change, I do see the expected UPDATE.

My Embeddable does have hashCode() and equals() implemented such that the changed map is not equal() to the former version in either case.

This looks like a bug in the dirty-checking logic in OpenJPA.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-1784) Map value updates not flushed

Posted by "Fay Wang (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1784?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Fay Wang updated OPENJPA-1784:
------------------------------

    Attachment: OPENJPA-1784.patch

> Map value updates not flushed
> -----------------------------
>
>                 Key: OPENJPA-1784
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1784
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc
>    Affects Versions: 2.0.1
>            Reporter: Harald Wellmann
>            Assignee: Fay Wang
>         Attachments: MapUpdate.patch, OPENJPA-1784.patch
>
>
> I have an entity with a map element collection where the map value is an Embeddable.
> @Embeddable
> public class LocalizedString {
>     private String language;
>     private String string;
>     // getters and setters omitted
> }
>  
> @Entity
> public class MultilingualString {
>     @Id
>     private long id;
>     @ElementCollection(fetch=FetchType.EAGER)
>     private Map<String, LocalizedString> map = new HashMap<String, LocalizedString>();
> }
> Given a persistent instance m of my entity, I update a member of a given map value and then merge the modified entity:
>     EntityManager em = ...;
>     em.getTransaction().begin();
>     m.getMap().get("en").setString("foo");
>     em.merge(m)
>     em.getTransaction().commit();
>    
> The problem is, the state change of the map does not get saved to the database. With DEBUG logging on, I can see that the flush on commit does not trigger any SQL UPDATE.
> To force the update, I have to put a new value into the map instead of just changing the existing one.
>     EntityManager em = ...;
>     em.getTransaction().begin();
>     m.getMap().put("en"), new LocalizedString("en", "foo"));
>     em.merge(m)
>     em.getTransaction().commit();
> After this change, I do see the expected UPDATE.
> My Embeddable does have hashCode() and equals() implemented such that the changed map is not equal() to the former version in either case.
> This looks like a bug in the dirty-checking logic in OpenJPA.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-1784) Map value updates not flushed

Posted by "Harald Wellmann (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1784?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Harald Wellmann updated OPENJPA-1784:
-------------------------------------

    Attachment: MapUpdate.patch

Unit test exhibiting the problem. A test which updates a map key passes. Another test which only update the map value fails.

> Map value updates not flushed
> -----------------------------
>
>                 Key: OPENJPA-1784
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1784
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc
>    Affects Versions: 2.0.1
>            Reporter: Harald Wellmann
>         Attachments: MapUpdate.patch
>
>
> I have an entity with a map element collection where the map value is an Embeddable.
> @Embeddable
> public class LocalizedString {
>     private String language;
>     private String string;
>     // getters and setters omitted
> }
>  
> @Entity
> public class MultilingualString {
>     @Id
>     private long id;
>     @ElementCollection(fetch=FetchType.EAGER)
>     private Map<String, LocalizedString> map = new HashMap<String, LocalizedString>();
> }
> Given a persistent instance m of my entity, I update a member of a given map value and then merge the modified entity:
>     EntityManager em = ...;
>     em.getTransaction().begin();
>     m.getMap().get("en").setString("foo");
>     em.merge(m)
>     em.getTransaction().commit();
>    
> The problem is, the state change of the map does not get saved to the database. With DEBUG logging on, I can see that the flush on commit does not trigger any SQL UPDATE.
> To force the update, I have to put a new value into the map instead of just changing the existing one.
>     EntityManager em = ...;
>     em.getTransaction().begin();
>     m.getMap().put("en"), new LocalizedString("en", "foo"));
>     em.merge(m)
>     em.getTransaction().commit();
> After this change, I do see the expected UPDATE.
> My Embeddable does have hashCode() and equals() implemented such that the changed map is not equal() to the former version in either case.
> This looks like a bug in the dirty-checking logic in OpenJPA.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1784) Map value updates not flushed

Posted by "Fay Wang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1784?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12907277#action_12907277 ] 

Fay Wang commented on OPENJPA-1784:
-----------------------------------

Change in persistent map are detected by OpenJPA when the the put/remove method is called. In the example, the get method is called to retrieve the value. Currently there is no way for the persistent map to know whether the value is modified or not. A new mechanism needs to be added to detect the change. 

> Map value updates not flushed
> -----------------------------
>
>                 Key: OPENJPA-1784
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1784
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc
>    Affects Versions: 2.0.1
>            Reporter: Harald Wellmann
>         Attachments: MapUpdate.patch
>
>
> I have an entity with a map element collection where the map value is an Embeddable.
> @Embeddable
> public class LocalizedString {
>     private String language;
>     private String string;
>     // getters and setters omitted
> }
>  
> @Entity
> public class MultilingualString {
>     @Id
>     private long id;
>     @ElementCollection(fetch=FetchType.EAGER)
>     private Map<String, LocalizedString> map = new HashMap<String, LocalizedString>();
> }
> Given a persistent instance m of my entity, I update a member of a given map value and then merge the modified entity:
>     EntityManager em = ...;
>     em.getTransaction().begin();
>     m.getMap().get("en").setString("foo");
>     em.merge(m)
>     em.getTransaction().commit();
>    
> The problem is, the state change of the map does not get saved to the database. With DEBUG logging on, I can see that the flush on commit does not trigger any SQL UPDATE.
> To force the update, I have to put a new value into the map instead of just changing the existing one.
>     EntityManager em = ...;
>     em.getTransaction().begin();
>     m.getMap().put("en"), new LocalizedString("en", "foo"));
>     em.merge(m)
>     em.getTransaction().commit();
> After this change, I do see the expected UPDATE.
> My Embeddable does have hashCode() and equals() implemented such that the changed map is not equal() to the former version in either case.
> This looks like a bug in the dirty-checking logic in OpenJPA.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (OPENJPA-1784) Map value updates not flushed

Posted by "Harald Wellmann (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1784?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12907210#action_12907210 ] 

Harald Wellmann edited comment on OPENJPA-1784 at 9/8/10 9:37 AM:
------------------------------------------------------------------

The attachment MapUpdate.patch contains a unit test exhibiting the problem. A test which updates a map key passes. Another test which only update the map value fails.

      was (Author: hwellmann):
    Unit test exhibiting the problem. A test which updates a map key passes. Another test which only update the map value fails.
  
> Map value updates not flushed
> -----------------------------
>
>                 Key: OPENJPA-1784
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1784
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc
>    Affects Versions: 2.0.1
>            Reporter: Harald Wellmann
>         Attachments: MapUpdate.patch
>
>
> I have an entity with a map element collection where the map value is an Embeddable.
> @Embeddable
> public class LocalizedString {
>     private String language;
>     private String string;
>     // getters and setters omitted
> }
>  
> @Entity
> public class MultilingualString {
>     @Id
>     private long id;
>     @ElementCollection(fetch=FetchType.EAGER)
>     private Map<String, LocalizedString> map = new HashMap<String, LocalizedString>();
> }
> Given a persistent instance m of my entity, I update a member of a given map value and then merge the modified entity:
>     EntityManager em = ...;
>     em.getTransaction().begin();
>     m.getMap().get("en").setString("foo");
>     em.merge(m)
>     em.getTransaction().commit();
>    
> The problem is, the state change of the map does not get saved to the database. With DEBUG logging on, I can see that the flush on commit does not trigger any SQL UPDATE.
> To force the update, I have to put a new value into the map instead of just changing the existing one.
>     EntityManager em = ...;
>     em.getTransaction().begin();
>     m.getMap().put("en"), new LocalizedString("en", "foo"));
>     em.merge(m)
>     em.getTransaction().commit();
> After this change, I do see the expected UPDATE.
> My Embeddable does have hashCode() and equals() implemented such that the changed map is not equal() to the former version in either case.
> This looks like a bug in the dirty-checking logic in OpenJPA.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (OPENJPA-1784) Map value updates not flushed

Posted by "Fay Wang (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1784?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Fay Wang resolved OPENJPA-1784.
-------------------------------

    Fix Version/s: 2.0.1
       Resolution: Fixed

> Map value updates not flushed
> -----------------------------
>
>                 Key: OPENJPA-1784
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1784
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc
>    Affects Versions: 2.0.1
>            Reporter: Harald Wellmann
>            Assignee: Fay Wang
>             Fix For: 2.0.1
>
>         Attachments: MapUpdate.patch, OPENJPA-1784.patch
>
>
> I have an entity with a map element collection where the map value is an Embeddable.
> @Embeddable
> public class LocalizedString {
>     private String language;
>     private String string;
>     // getters and setters omitted
> }
>  
> @Entity
> public class MultilingualString {
>     @Id
>     private long id;
>     @ElementCollection(fetch=FetchType.EAGER)
>     private Map<String, LocalizedString> map = new HashMap<String, LocalizedString>();
> }
> Given a persistent instance m of my entity, I update a member of a given map value and then merge the modified entity:
>     EntityManager em = ...;
>     em.getTransaction().begin();
>     m.getMap().get("en").setString("foo");
>     em.merge(m)
>     em.getTransaction().commit();
>    
> The problem is, the state change of the map does not get saved to the database. With DEBUG logging on, I can see that the flush on commit does not trigger any SQL UPDATE.
> To force the update, I have to put a new value into the map instead of just changing the existing one.
>     EntityManager em = ...;
>     em.getTransaction().begin();
>     m.getMap().put("en"), new LocalizedString("en", "foo"));
>     em.merge(m)
>     em.getTransaction().commit();
> After this change, I do see the expected UPDATE.
> My Embeddable does have hashCode() and equals() implemented such that the changed map is not equal() to the former version in either case.
> This looks like a bug in the dirty-checking logic in OpenJPA.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (OPENJPA-1784) Map value updates not flushed

Posted by "Fay Wang (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1784?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Fay Wang reassigned OPENJPA-1784:
---------------------------------

    Assignee: Fay Wang

> Map value updates not flushed
> -----------------------------
>
>                 Key: OPENJPA-1784
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1784
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc
>    Affects Versions: 2.0.1
>            Reporter: Harald Wellmann
>            Assignee: Fay Wang
>         Attachments: MapUpdate.patch
>
>
> I have an entity with a map element collection where the map value is an Embeddable.
> @Embeddable
> public class LocalizedString {
>     private String language;
>     private String string;
>     // getters and setters omitted
> }
>  
> @Entity
> public class MultilingualString {
>     @Id
>     private long id;
>     @ElementCollection(fetch=FetchType.EAGER)
>     private Map<String, LocalizedString> map = new HashMap<String, LocalizedString>();
> }
> Given a persistent instance m of my entity, I update a member of a given map value and then merge the modified entity:
>     EntityManager em = ...;
>     em.getTransaction().begin();
>     m.getMap().get("en").setString("foo");
>     em.merge(m)
>     em.getTransaction().commit();
>    
> The problem is, the state change of the map does not get saved to the database. With DEBUG logging on, I can see that the flush on commit does not trigger any SQL UPDATE.
> To force the update, I have to put a new value into the map instead of just changing the existing one.
>     EntityManager em = ...;
>     em.getTransaction().begin();
>     m.getMap().put("en"), new LocalizedString("en", "foo"));
>     em.merge(m)
>     em.getTransaction().commit();
> After this change, I do see the expected UPDATE.
> My Embeddable does have hashCode() and equals() implemented such that the changed map is not equal() to the former version in either case.
> This looks like a bug in the dirty-checking logic in OpenJPA.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-1784) Map value updates not flushed

Posted by "Milosz Tylenda (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1784?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Milosz Tylenda updated OPENJPA-1784:
------------------------------------

    Fix Version/s: 2.1.0
                       (was: 2.0.1)

> Map value updates not flushed
> -----------------------------
>
>                 Key: OPENJPA-1784
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1784
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc
>    Affects Versions: 2.0.1
>            Reporter: Harald Wellmann
>            Assignee: Fay Wang
>             Fix For: 2.1.0
>
>         Attachments: MapUpdate.patch, OPENJPA-1784.patch
>
>
> I have an entity with a map element collection where the map value is an Embeddable.
> @Embeddable
> public class LocalizedString {
>     private String language;
>     private String string;
>     // getters and setters omitted
> }
>  
> @Entity
> public class MultilingualString {
>     @Id
>     private long id;
>     @ElementCollection(fetch=FetchType.EAGER)
>     private Map<String, LocalizedString> map = new HashMap<String, LocalizedString>();
> }
> Given a persistent instance m of my entity, I update a member of a given map value and then merge the modified entity:
>     EntityManager em = ...;
>     em.getTransaction().begin();
>     m.getMap().get("en").setString("foo");
>     em.merge(m)
>     em.getTransaction().commit();
>    
> The problem is, the state change of the map does not get saved to the database. With DEBUG logging on, I can see that the flush on commit does not trigger any SQL UPDATE.
> To force the update, I have to put a new value into the map instead of just changing the existing one.
>     EntityManager em = ...;
>     em.getTransaction().begin();
>     m.getMap().put("en"), new LocalizedString("en", "foo"));
>     em.merge(m)
>     em.getTransaction().commit();
> After this change, I do see the expected UPDATE.
> My Embeddable does have hashCode() and equals() implemented such that the changed map is not equal() to the former version in either case.
> This looks like a bug in the dirty-checking logic in OpenJPA.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.