Hi,
I have the following test class that is failing when the enhancer is enabled, resulting in the error 'Failed to write the value of field field TestEmbeddableMap$MyAttributeItem.id using enhanced method.', if I disable the enhancement the test works as expected, and returns the expected MyEntity2
Thanks
import java.util.LinkedHashMap; import javax.persistence.Embeddable; import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; public class TestEmbeddableMap { public static void main(String[] args) { EntityManagerFactory emf = Persistence.createEntityManagerFactory( "objectdb:$objectdb/db/test_embed.tmp;drop"); EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); MyEntity2 entity = new MyEntity2("entity1"); entity.put("key1", new MyAttributeItem("id1", "name1", "value1")); entity.put("key2", new MyAttributeItem("id2", "name2", "value2")); entity.put("key3", new MyAttributeItem("id3", "name3", "value3")); em.persist(entity); MyEntity2 entity2 = new MyEntity2("entity2"); entity2.put("key1", new MyAttributeItem("id1", "name1", "value4")); entity2.put("key2", new MyAttributeItem("id2", "name2", "value5")); entity2.put("key3", new MyAttributeItem("id3", "name3", "value6")); em.persist(entity2); em.getTransaction().commit(); System.out.println("In Query"); for (MyEntity2 myEntity : em.createQuery("select e from MyEntity2 e", MyEntity2.class).getResultList()) { System.out.println(myEntity); } System.out.println("Queries on attributes, should return entity1"); for (MyEntity2 myEntity2 : em.createQuery("select from MyEntity2 e where e.values.get('key1').value = 'value1'", MyEntity2.class).getResultList()) { System.out.println(myEntity2); } } @Entity public static class MyEntity2 { private String name; private LinkedHashMap<String, MyAttributeItem> values = new LinkedHashMap<>(); public MyEntity2(String name) { super(); this.name = name; } public MyAttributeItem get(Object key) { return values.get(key); } public MyAttributeItem put(String key, MyAttributeItem value) { return values.put(key, value); } @Override public String toString() { return "MyEntity2 [name=" + name + ", values=" + values + "]"; } } @Embeddable public static class MyAttributeItem { private String id; private String name; private String value; public MyAttributeItem(String id, String name, String value) { super(); this.id = id; this.name = name; this.value = value; } @Override public String toString() { return "MyAttributeItem [id=" + id + ", name=" + name + ", value=" + value + "]"; } } }
Exception in thread "main" [ObjectDB 2.6.4_03] javax.persistence.PersistenceException Failed to write the value of field field TestEmbeddableMap$MyAttributeItem.id using enhanced method (error 362) at com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:725) at TestEmbeddableMap.main(TestEmbeddableMap.java:40) Caused by: com.objectdb.o.UserException: Failed to write the value of field field TestEmbeddableMap$MyAttributeItem.id using enhanced method at com.objectdb.o.MSG.d(MSG.java:75) at com.objectdb.o.UMR.P(UMR.java:932) at com.objectdb.o.UMR.z(UMR.java:574) at com.objectdb.o.UML.u(UML.java:537) at com.objectdb.o.REG.y(REG.java:266) at com.objectdb.o.QUN.E(QUN.java:452) at com.objectdb.o.CLN$aA.T(CLN.java:456) at com.objectdb.o.PTN.T(PTN.java:503) at com.objectdb.o.PTN.T(PTN.java:481) at com.objectdb.o.PTN.T(PTN.java:481) at com.objectdb.o.QUN.UB(QUN.java:686) at com.objectdb.o.BCN.o(BCN.java:311) at com.objectdb.o.BCN.Vd(BCN.java:264) at com.objectdb.o.PBI.C(PBI.java:146) at com.objectdb.o.PBI.q(PBI.java:115) at com.objectdb.o.OBI.VA(OBI.java:244) at com.objectdb.o.BQI.VK(BQI.java:151) at com.objectdb.o.PRG.ai(PRG.java:782) at com.objectdb.o.PRG.ag(PRG.java:711) at com.objectdb.o.PRG.af(PRG.java:553) at com.objectdb.o.QRM.Vm(QRM.java:286) at com.objectdb.o.MST.Vm(MST.java:988) at com.objectdb.o.WRA.Vm(WRA.java:311) at com.objectdb.o.WSM.Vm(WSM.java:115) at com.objectdb.o.QRR.g(QRR.java:247) at com.objectdb.o.QRR.f(QRR.java:153) at com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:716) ... 1 more Caused by: java.lang.IllegalArgumentException at TestEmbeddableMap$MyAttributeItem.__odbWriteMember(TestEmbeddableMap.java:1) at com.objectdb.o.UMR.A(UMR.java:587) at com.objectdb.o.UMR.z(UMR.java:571) ... 25 more