You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Harald Wellmann <Ha...@multi-m.de> on 2010/08/20 18:11:39 UTC

Bug or Feature: Persistent Map Merge Behaviour

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 text;

    // 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").setText("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.

Is this the expected behaviour, or is there a bug in the dirty-checking
logic in OpenJPA?

Best regards,

Harald




-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Bug-or-Feature-Persistent-Map-Merge-Behaviour-tp5445062p5445062.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Bug or Feature: Persistent Map Merge Behaviour

Posted by Harald Wellmann <Ha...@multi-m.de>.

Rick Curtis wrote:
> 
> Are you using a DetachedStateManager? 
> 

I don't think so - I'm just using the official JPA APIs in this context and
no OpenJPA specifics.

I can't post my persistence.xml, but I can try to isolate a simple test case
and post that.

Regards,
Harald

-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Bug-or-Feature-Persistent-Map-Merge-Behaviour-tp5445062p5448008.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Bug or Feature: Persistent Map Merge Behaviour

Posted by Rick Curtis <cu...@gmail.com>.
Harold -

Are you using a DetachedStateManager? If so, this sounds like it might be a
bug?

Can you post the contents of your persistence.xml file?

Thanks,
Rick

On Fri, Aug 20, 2010 at 11:11 AM, Harald Wellmann <
Harald.Wellmann@multi-m.de> wrote:

>
> 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 text;
>
>    // 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").setText("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.
>
> Is this the expected behaviour, or is there a bug in the dirty-checking
> logic in OpenJPA?
>
> Best regards,
>
> Harald
>
>

Re: Bug or Feature: Persistent Map Merge Behaviour

Posted by Harald Wellmann <Ha...@multi-m.de>.
I created a bug report for this issue:
https://issues.apache.org/jira/browse/OPENJPA-1784

I've attached a patch file with a unit test exposing the problem, trying to
follow the guidelines on the OpenJPA homepage. Hope I didn't miss anything
important.

Best regards,

Harald

-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Bug-or-Feature-Persistent-Map-Merge-Behaviour-tp5445062p5510658.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.