You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by rz...@apache.org on 2026/10/23 12:50:06 UTC

(openjpa) 01/01: [OPENJPA-3019] Write an in-place change to an element of a collection converted as a whole

This is an automated email from the ASF dual-hosted git repository.

rzo1 pushed a commit to branch OPENJPA-3019
in repository https://gitbox.apache.org/repos/asf/openjpa.git

commit 4dd1fd34ba85d480c5cf75b68e45473ad78696e7
Author: Richard Zowalla <rz...@apache.org>
AuthorDate: Fri Oct 23 14:49:55 2026 +0200

    [OPENJPA-3019] Write an in-place change to an element of a collection converted as a whole
    
    The proxy of such a collection only sees adds and removes, so a change made
    inside an element was never written. The converted value of these fields is
    now saved when they are loaded, and compared once before each flush; a field
    whose converted value differs is marked dirty.
---
 .../java/org/apache/openjpa/kernel/BrokerImpl.java |  44 ++++++
 .../apache/openjpa/kernel/StateManagerImpl.java    |  61 +++++++-
 .../org/apache/openjpa/meta/ClassMetaData.java     |  31 +++++
 .../conversion/InPlaceConvertedEntity.java         |  71 ++++++++++
 .../persistence/conversion/ItemConverter.java      |  39 ++++++
 .../persistence/conversion/ItemMapConverter.java   |  61 ++++++++
 .../conversion/TestConvertedInPlaceChange.java     | 153 +++++++++++++++++++++
 7 files changed, 459 insertions(+), 1 deletion(-)

diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
index ff93cc39f..defb57cf8 100644
--- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
+++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
@@ -41,6 +41,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.WeakHashMap;
 import java.util.concurrent.locks.ReentrantLock;
 
 import jakarta.transaction.Status;
@@ -197,6 +198,10 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl
     private Set<StateManagerImpl> _derefCache = null;
     private Set<StateManagerImpl> _derefAdditions = null;
 
+    // instances with a collection or map field that is converted as a whole,
+    // held weakly; checked at flush for elements changed in place
+    private transient Set<StateManagerImpl> _wholeConverted = null;
+
     // these are used for method-internal state only
     private transient Map<Object, StateManagerImpl> _loading = null;
     private transient Set<Object> _operating = null;
@@ -2217,6 +2222,7 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl
     protected void flush(int reason) {
         // this will enlist proxied states as necessary so we know whether we
         // have anything to flush
+        dirtyCheckWholeConverted();
         Collection transactional = getTransactionalStates();
 
         // do we actually have to flush?  only if our flags say so, or if
@@ -3655,6 +3661,7 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl
         if (_transCache != null) {
             _transCache.clear();
         }
+        _wholeConverted = null;
         if (_transAdditions != null) {
             _transAdditions.clear();
         }
@@ -4311,12 +4318,44 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl
      * Return a copy of all dirty state managers.
      */
     protected Collection getDirtyStates() {
+        dirtyCheckWholeConverted();
         if (!hasTransactionalObjects())
             return Collections.EMPTY_SET;
 
         return _transCache.copyDirty();
     }
 
+    /**
+     * Notify the broker that the given instance has a collection or map
+     * field that is converted as a whole, so that an element changed in
+     * place is found at flush.
+     */
+    void addWholeConverted(StateManagerImpl sm) {
+        lock();
+        try {
+            if (_wholeConverted == null)
+                _wholeConverted = Collections.newSetFromMap(new WeakHashMap<>());
+            _wholeConverted.add(sm);
+        } finally {
+            unlock();
+        }
+    }
+
+    /**
+     * Mark dirty the collection and map fields converted as a whole whose
+     * elements were changed in place. This is done once before a flush
+     * rather than on every dirty check, since it runs the converters.
+     */
+    private void dirtyCheckWholeConverted() {
+        if (_wholeConverted == null || _wholeConverted.isEmpty()
+            || (_flags & FLAG_ACTIVE) == 0)
+            return;
+
+        // iterate over a copy, since dirtying an instance enlists it again
+        for (StateManagerImpl sm : new ArrayList<>(_wholeConverted))
+            sm.dirtyCheckWholeConverted();
+    }
+
     /**
      * Return a copy of all state managers which will become
      * transactional upon the next transaction.
@@ -4374,6 +4413,8 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl
     void addToTransaction(StateManagerImpl sm) {
         // we only add clean instances now; dirty instances are added in
         // the setDirty callback
+        if (sm.getMetaData().getWholeConvertedFields().length > 0)
+            addWholeConverted(sm);
         if (sm.isDirty())
             return;
 
@@ -4400,6 +4441,8 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl
                 _transCache.remove(sm);
             if (_derefCache != null && !sm.isPersistent())
                 _derefCache.remove(sm);
+            if (_wholeConverted != null && !sm.isPersistent())
+                _wholeConverted.remove(sm);
         } finally {
             unlock();
         }
@@ -4628,6 +4671,7 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl
         _updatedClss = null;
         _deletedClss = null;
         _derefCache = null;
+        _wholeConverted = null;
         _pending = null;
         _loader = null;
         _transEventManager = null;
diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
index 4a538d80e..036578074 100644
--- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
+++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
@@ -149,6 +149,12 @@ public class StateManagerImpl implements OpenJPAStateManager, Serializable {
     private SaveFieldManager _saved = null;
     private FieldManager _fm = null;
 
+    // converted value of each collection or map field that is converted as a
+    // whole, as last loaded or dirty checked; indexed by field, and set in
+    // _wholeConvertedSaved once saved
+    private Object[] _wholeConverted = null;
+    private BitSet _wholeConvertedSaved = null;
+
     // impldata; field impldata and intermediate data share the same array
     private Object _impl = null;
     protected Object[] _fieldImpl = null;
@@ -984,6 +990,53 @@ public class StateManagerImpl implements OpenJPAStateManager, Serializable {
         }
     }
 
+    /**
+     * Mark dirty each collection or map field that is converted as a whole
+     * and whose converted value differs from the one last seen. An element
+     * changed in place does not go through the proxy of the field, but it
+     * changes the converted column. Called by the broker before it flushes.
+     */
+    void dirtyCheckWholeConverted() {
+        FieldMetaData[] fmds = _meta.getWholeConvertedFields();
+        if (fmds.length == 0 || !isPersistent() || isDeleted())
+            return;
+
+        for (FieldMetaData fmd : fmds) {
+            int i = fmd.getIndex();
+            if (!_loaded.get(i))
+                continue;
+            // a new instance has no saved value until its first check
+            boolean saved = _wholeConvertedSaved != null
+                && _wholeConvertedSaved.get(i);
+            Object last = saved ? _wholeConverted[i] : null;
+            Object val = saveWholeConverted(i);
+            if (saved && !Objects.deepEquals(last, val))
+                dirty(i);
+        }
+    }
+
+    /**
+     * Remember the converted value of the given field if it is a collection
+     * or map that is converted as a whole, and return it.
+     */
+    private Object saveWholeConverted(int field) {
+        FieldMetaData[] fmds = _meta.getWholeConvertedFields();
+        for (FieldMetaData fmd : fmds) {
+            if (fmd.getIndex() == field) {
+                if (_wholeConverted == null) {
+                    _wholeConverted = new Object[_meta.getFields().length];
+                    _wholeConvertedSaved = new BitSet(_wholeConverted.length);
+                    _broker.addWholeConverted(this);
+                }
+                Object val = fetch(field);
+                _wholeConverted[field] = val;
+                _wholeConvertedSaved.set(field);
+                return val;
+            }
+        }
+        return null;
+    }
+
     private boolean needsDirtyCheck() {
         if (isIntercepting())
             return false;
@@ -2809,6 +2862,7 @@ public class StateManagerImpl implements OpenJPAStateManager, Serializable {
             _single.proxy(true, false);
             replaceField(_pc, _single, field);
             setLoaded(field, true);
+            saveWholeConverted(field);
             postLoad(field, null);
         } finally {
             unlock();
@@ -3414,8 +3468,13 @@ public class StateManagerImpl implements OpenJPAStateManager, Serializable {
 
         if (isLoaded)
             _loaded.set(field);
-        else
+        else {
             _loaded.clear(field);
+            if (_wholeConvertedSaved != null) {
+                _wholeConvertedSaved.clear(field);
+                _wholeConverted[field] = null;
+            }
+        }
     }
 
     /**
diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
index b2345645e..fcadcd384 100644
--- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
+++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
@@ -218,6 +218,7 @@ public class ClassMetaData
     private FieldMetaData[] _allListingFields = null;
     private FieldMetaData[] _allProxyFields = null;
     private FieldMetaData[] _allLrsFields = null;
+    private FieldMetaData[] _allWholeConvertedFields = null;
     private FetchGroup[] _fgs = null;
     private FetchGroup[] _customFGs = null;
     private boolean _intercepting = false;
@@ -1050,6 +1051,35 @@ public class ClassMetaData
         return _allProxyFields;
     }
 
+    /**
+     * Return all collection and map fields whose value is converted as a
+     * whole by an AttributeConverter (see
+     * {@link FieldMetaData#convertsWholeValue()}). Their proxy tracks only
+     * structural changes, while the converted column also depends on the
+     * state of the elements. Will never return null.
+     */
+    public FieldMetaData[] getWholeConvertedFields() {
+        if (_allWholeConvertedFields == null) {
+            // Make sure _allFields has been initialized
+            if (_allFields == null) {
+                getFields();
+            }
+            List<FieldMetaData> res = new ArrayList<>();
+            for (FieldMetaData fmd : _allFields) {
+                switch (fmd.getDeclaredTypeCode()) {
+                    case JavaTypes.COLLECTION:
+                    case JavaTypes.MAP:
+                        if (fmd.convertsWholeValue()) {
+                            res.add(fmd);
+                        }
+                        break;
+                }
+            }
+            _allWholeConvertedFields = res.toArray(new FieldMetaData[0]);
+        }
+        return _allWholeConvertedFields;
+    }
+
     /**
      * Return all large result set fields. Will never return null.
      */
@@ -1703,6 +1733,7 @@ public class ClassMetaData
         _allPKFields = null;
         _allProxyFields = null;
         _allLrsFields = null;
+        _allWholeConvertedFields = null;
         _definedFields = null;
         _listingFields = null;
         _allListingFields = null;
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conversion/InPlaceConvertedEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conversion/InPlaceConvertedEntity.java
new file mode 100644
index 000000000..0de8dfc47
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conversion/InPlaceConvertedEntity.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.conversion;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import jakarta.persistence.Convert;
+import jakarta.persistence.Entity;
+import jakarta.persistence.Id;
+
+/**
+ * Converted attributes of mutable types, changed in place by the tests.
+ */
+@Entity
+public class InPlaceConvertedEntity {
+
+    @Id
+    private long id;
+
+    @Convert(converter = ItemListConverter.class)
+    private List<Item> items = new ArrayList<>();
+
+    @Convert(converter = ItemMapConverter.class)
+    private Map<String, Item> itemsByKey = new LinkedHashMap<>();
+
+    @Convert(converter = ItemConverter.class)
+    private Item item;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public List<Item> getItems() {
+        return items;
+    }
+
+    public Map<String, Item> getItemsByKey() {
+        return itemsByKey;
+    }
+
+    public Item getItem() {
+        return item;
+    }
+
+    public void setItem(Item item) {
+        this.item = item;
+    }
+}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conversion/ItemConverter.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conversion/ItemConverter.java
new file mode 100644
index 000000000..3c848f97f
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conversion/ItemConverter.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.conversion;
+
+import jakarta.persistence.AttributeConverter;
+import jakarta.persistence.Converter;
+
+/**
+ * Converts a single, mutable {@link Item} to its name.
+ */
+@Converter
+public class ItemConverter implements AttributeConverter<Item, String> {
+
+    @Override
+    public String convertToDatabaseColumn(Item attribute) {
+        return attribute == null ? null : attribute.getName();
+    }
+
+    @Override
+    public Item convertToEntityAttribute(String dbData) {
+        return dbData == null ? null : new Item(dbData);
+    }
+}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conversion/ItemMapConverter.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conversion/ItemMapConverter.java
new file mode 100644
index 000000000..594682532
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conversion/ItemMapConverter.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.conversion;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import jakarta.persistence.AttributeConverter;
+import jakarta.persistence.Converter;
+
+/**
+ * Converts the whole map to one string of key=name pairs, so the attribute
+ * type the converter declares is the map itself.
+ */
+@Converter
+public class ItemMapConverter implements AttributeConverter<Map<String, Item>, String> {
+
+    @Override
+    public String convertToDatabaseColumn(Map<String, Item> attribute) {
+        if (attribute == null) {
+            return null;
+        }
+        StringBuilder sb = new StringBuilder();
+        for (Map.Entry<String, Item> e : attribute.entrySet()) {
+            if (sb.length() > 0) {
+                sb.append(',');
+            }
+            sb.append(e.getKey()).append('=').append(e.getValue().getName());
+        }
+        return sb.toString();
+    }
+
+    @Override
+    public Map<String, Item> convertToEntityAttribute(String dbData) {
+        Map<String, Item> items = new LinkedHashMap<>();
+        if (dbData == null || dbData.isEmpty()) {
+            return items;
+        }
+        for (String pair : dbData.split(",")) {
+            int eq = pair.indexOf('=');
+            items.put(pair.substring(0, eq), new Item(pair.substring(eq + 1)));
+        }
+        return items;
+    }
+}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conversion/TestConvertedInPlaceChange.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conversion/TestConvertedInPlaceChange.java
new file mode 100644
index 000000000..534c7d0dd
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conversion/TestConvertedInPlaceChange.java
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.conversion;
+
+import jakarta.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+/**
+ * A change made in place to the mutable value of a converted attribute is a
+ * change of the entity and has to be written at flush, as the specification
+ * requires in "Synchronization to the Database".
+ */
+public class TestConvertedInPlaceChange extends SQLListenerTestCase {
+
+    @Override
+    public void setUp() {
+        setUp(InPlaceConvertedEntity.class, CLEAR_TABLES);
+        try (EntityManager em = emf.createEntityManager()) {
+            em.getTransaction().begin();
+            InPlaceConvertedEntity e = new InPlaceConvertedEntity();
+            e.setId(1L);
+            e.getItems().add(new Item("one"));
+            e.getItems().add(new Item("two"));
+            e.getItemsByKey().put("a", new Item("one"));
+            e.setItem(new Item("single"));
+            em.persist(e);
+            em.getTransaction().commit();
+        }
+    }
+
+    public void testElementOfConvertedListChangedInPlace() {
+        try (EntityManager em = emf.createEntityManager()) {
+            em.getTransaction().begin();
+            em.find(InPlaceConvertedEntity.class, 1L).getItems().get(0).setName("changed");
+            em.getTransaction().commit();
+        }
+        try (EntityManager em = emf.createEntityManager()) {
+            assertEquals("changed",
+                em.find(InPlaceConvertedEntity.class, 1L).getItems().get(0).getName());
+        }
+    }
+
+    public void testElementOfConvertedMapChangedInPlace() {
+        try (EntityManager em = emf.createEntityManager()) {
+            em.getTransaction().begin();
+            em.find(InPlaceConvertedEntity.class, 1L).getItemsByKey().get("a").setName("changed");
+            em.getTransaction().commit();
+        }
+        try (EntityManager em = emf.createEntityManager()) {
+            assertEquals("changed",
+                em.find(InPlaceConvertedEntity.class, 1L).getItemsByKey().get("a").getName());
+        }
+    }
+
+    /**
+     * A change made after a flush is written by the next flush, and so is
+     * one made to a new instance after it was inserted.
+     */
+    public void testElementOfConvertedListChangedAfterFlush() {
+        try (EntityManager em = emf.createEntityManager()) {
+            em.getTransaction().begin();
+            InPlaceConvertedEntity e = em.find(InPlaceConvertedEntity.class, 1L);
+            e.getItems().get(0).setName("first");
+            em.flush();
+            e.getItems().get(0).setName("second");
+
+            InPlaceConvertedEntity n = new InPlaceConvertedEntity();
+            n.setId(2L);
+            n.getItems().add(new Item("new"));
+            em.persist(n);
+            em.flush();
+            n.getItems().get(0).setName("changed");
+            em.getTransaction().commit();
+        }
+        try (EntityManager em = emf.createEntityManager()) {
+            assertEquals("second",
+                em.find(InPlaceConvertedEntity.class, 1L).getItems().get(0).getName());
+            assertEquals("changed",
+                em.find(InPlaceConvertedEntity.class, 2L).getItems().get(0).getName());
+        }
+    }
+
+    /**
+     * An instance loaded outside a transaction, or kept from an earlier
+     * one, is checked too.
+     */
+    public void testElementOfConvertedListChangedInLaterTransaction() {
+        try (EntityManager em = emf.createEntityManager()) {
+            InPlaceConvertedEntity e = em.find(InPlaceConvertedEntity.class, 1L);
+            em.getTransaction().begin();
+            e.getItems().get(0).setName("first");
+            em.getTransaction().commit();
+
+            em.getTransaction().begin();
+            e.getItems().get(1).setName("second");
+            em.getTransaction().commit();
+        }
+        try (EntityManager em = emf.createEntityManager()) {
+            InPlaceConvertedEntity e = em.find(InPlaceConvertedEntity.class, 1L);
+            assertEquals("first", e.getItems().get(0).getName());
+            assertEquals("second", e.getItems().get(1).getName());
+        }
+    }
+
+    public void testUnchangedConvertedListIsNotWritten() {
+        try (EntityManager em = emf.createEntityManager()) {
+            em.getTransaction().begin();
+            assertEquals("one", em.find(InPlaceConvertedEntity.class, 1L).getItems().get(0).getName());
+            resetSQL();
+            em.getTransaction().commit();
+        }
+        assertNotSQL("UPDATE .*");
+    }
+
+    public void testConvertedValueChangedInPlace() {
+        try (EntityManager em = emf.createEntityManager()) {
+            em.getTransaction().begin();
+            em.find(InPlaceConvertedEntity.class, 1L).getItem().setName("changed");
+            em.getTransaction().commit();
+        }
+        try (EntityManager em = emf.createEntityManager()) {
+            assertEquals("changed", em.find(InPlaceConvertedEntity.class, 1L).getItem().getName());
+        }
+    }
+
+    public void testConvertedListChangedStructurally() {
+        try (EntityManager em = emf.createEntityManager()) {
+            em.getTransaction().begin();
+            em.find(InPlaceConvertedEntity.class, 1L).getItems().add(new Item("three"));
+            em.getTransaction().commit();
+        }
+        try (EntityManager em = emf.createEntityManager()) {
+            assertEquals(3, em.find(InPlaceConvertedEntity.class, 1L).getItems().size());
+        }
+    }
+}