hello support,
what is wrong?
---
package debug; import static java.lang.System.out; import static javax.persistence.GenerationType.IDENTITY; import static javax.persistence.Persistence.createEntityManagerFactory; import java.io.File; import java.util.List; import javax.persistence.Embeddable; import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; /** * @author Stanislav Jakuschev 14.08.2024 * * objectdb-2.9.0_03 * * issue: Inverse @OneToMany(mappedBy = "id.ab") into @EmbeddedId fails! * * question: Is it possible to map Entitys inverse OneToMany if this are * a part of EmbeddedId? */ public class OdbInverseEmbIdMapping { public static void main(String[] args) { String dbName = OdbInverseEmbIdMapping.class.getSimpleName() + ".odb"; new File(dbName).delete(); new File(dbName + "$").delete(); EntityManager em = createEntityManagerFactory(dbName).createEntityManager(); em.getTransaction().begin(); A a = new A(); B b = new B(); AB ab = new AB(a, b); em.persist(a); em.persist(b); em.persist(ab); em.getTransaction().commit(); em.getTransaction().begin(); em.persist(new C(new CId(ab, 1), 1)); em.persist(new C(new CId(ab, 2), 1)); em.getTransaction().commit(); em.clear(); out.println(em.createQuery("select a from A a", A.class).getResultList()); out.println(em.createQuery("select b from B b", B.class).getResultList()); List abs = em.createQuery("select ab from AB ab", AB.class).getResultList(); out.println(abs); out.println(em.createQuery("select c from C c", C.class).getResultList()); out.println(abs.get(0).cs); } @Entity public static class A { @Id @GeneratedValue(strategy = IDENTITY) public int id; @OneToMany(mappedBy = "a") public List abs; public A() { } @Override public String toString() { return "A [id=" + id + ", abs.size=" + abs.size() + "]"; } } @Entity public static class B { @Id @GeneratedValue(strategy = IDENTITY) public int id; @OneToMany(mappedBy = "b") public List abs; public B() { } @Override public String toString() { return "B [id=" + id + ", abs.size=" + abs.size() + "]"; } } @Entity public static class AB { @Id @GeneratedValue(strategy = IDENTITY) public int id; @ManyToOne() public A a; @ManyToOne() public B b; @OneToMany(mappedBy = "id.ab") public List cs; public AB() { } public AB(A a, B b) { this.a = a; this.b = b; } @Override public String toString() { return "AB [id=" + id + ", a=" + a + ", b=" + b + "]"; } } @Entity public static class C { @EmbeddedId private CId id; public int y; public C() { } public C(CId id, int y) { this.id = id; this.y = y; } @Override public String toString() { return "C [id=" + id + ", y=" + y + "]"; } } @Embeddable public static class CId { @ManyToOne() public AB ab; public int x; public CId() { } public CId(AB ab, int x) { this.ab = ab; this.x = x; } @Override public String toString() { return "CId [ab.id=" + ab.id + ", x=" + x + "]"; } } }
---
13:32:52.428 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Log4j2LoggerProvider 13:32:52.558 [main] INFO org.hibernate.jpa.boot.internal.PersistenceXmlParser - HHH000318: Could not find any META-INF/persistence.xml file in the classpath 13:32:52.560 [main] DEBUG org.hibernate.jpa.HibernatePersistenceProvider - Located and parsed 0 persistence units; checking each 13:32:52.562 [main] DEBUG org.hibernate.jpa.HibernatePersistenceProvider - Found no matching persistence units [A [id=1, abs.size=1]] [B [id=1, abs.size=1]] [AB [id=1, a=A [id=1, abs.size=1], b=B [id=1, abs.size=1]]] [C [id=CId [ab.id=1, x=1], y=1], C [id=CId [ab.id=1, x=2], y=1]] Exception in thread "main" [ObjectDB 2.9.0_03] javax.persistence.PersistenceException id.ab is not found in type C (mapped by [Single] field debug.OdbInverseEmbIdMapping$AB.cs null) (error 305) at java.lang.String.valueOf(String.java:2994) at java.io.PrintStream.println(PrintStream.java:821) at debug.OdbInverseEmbIdMapping.main(OdbInverseEmbIdMapping.java:67) Caused by: com.objectdb.o.UserException: id.ab is not found in type C (mapped by [Single] field debug.OdbInverseEmbIdMapping$AB.cs null) at com.objectdb.o.MSG.a(MSG.java:64) at com.objectdb.o.IMQ.<init>(IMQ.java:78) at com.objectdb.o.UMR.A(UMR.java:511) at com.objectdb.o.ENT.loadInverse(ENT.java:1565) at com.objectdb.o.IVP.h(IVP.java:151) ... 5 more
---
Thank You!