org.hibernate.AnnotationException: Foreign key circularity dependency involving the following tables: D, C, A

Hibernate JIRA | Sven Woltmann | 9 years ago
  1. 0

    The bug described in ANN-694 still exists in 3.3.1.GA under the following circumstances (see below for further description): ------------------------------------------------------------ @Entity public class A_PK implements Serializable { public D d; @ManyToOne public D getD() { return d; } public void setD(D d) { this.d = d; } } ------------------------------------------------------------ @Entity public class A implements Serializable { private A_PK id; @EmbeddedId public A_PK getId() { return id; } public void setId(A_PK id) { this.id = id; } } ------------------------------------------------------------ @Entity @Inheritance(strategy = InheritanceType.JOINED) public class B implements Serializable { @Id private int id; } ------------------------------------------------------------ @Entity public class C extends B implements Serializable { } ------------------------------------------------------------ public class D_PK implements Serializable { private C c; @ManyToOne public C getC() { return c; } public void setC(C c) { this.c = c; } } ------------------------------------------------------------ @Entity public class D implements Serializable { private D_PK id; @EmbeddedId public D_PK getId() { return id; } public void setId(D_PK id) { this.id = id; } } ------------------------------------------------------------ The references are as follows - there are no circularity dependencies: A --> A_PK --> D --> D_PK --> C --> B ------------------------------------------------------------ Hibernate throws the following exception: org.hibernate.AnnotationException: Foreign key circularity dependency involving the following tables: D, C, A at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:470) at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:304) at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:762) at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:93) at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:61) at test.DoTest.initTest(DoTest.java:22) ------------------------------------------------------------ When I do any of the following, *no* exception is thrown: - class A_PK: reference "C" instead of "D" (removing "C" from the dependency chain) - class A: move annotation from getter to field declaration "private A_PK id" - class A: replace embedded id "A_PK" by reference to "D" (as in "A_PK") - class A: rename class to "Z" - class B: remove "strategy" parameter from "@Inheritance" annotation - class C: not extending "B" and defining the primary key in "C" - class C: rename class to "Z" - class D: move annotation from getter to field declaration "private D_PK id" - class D: replace embedded id "D_PK" by reference to "C" (as in "D_PK") Attached you'll find a test case.

    Hibernate JIRA | 9 years ago | Sven Woltmann
    org.hibernate.AnnotationException: Foreign key circularity dependency involving the following tables: D, C, A
  2. 0

    The bug described in ANN-694 still exists in 3.3.1.GA under the following circumstances (see below for further description): ------------------------------------------------------------ @Entity public class A_PK implements Serializable { public D d; @ManyToOne public D getD() { return d; } public void setD(D d) { this.d = d; } } ------------------------------------------------------------ @Entity public class A implements Serializable { private A_PK id; @EmbeddedId public A_PK getId() { return id; } public void setId(A_PK id) { this.id = id; } } ------------------------------------------------------------ @Entity @Inheritance(strategy = InheritanceType.JOINED) public class B implements Serializable { @Id private int id; } ------------------------------------------------------------ @Entity public class C extends B implements Serializable { } ------------------------------------------------------------ public class D_PK implements Serializable { private C c; @ManyToOne public C getC() { return c; } public void setC(C c) { this.c = c; } } ------------------------------------------------------------ @Entity public class D implements Serializable { private D_PK id; @EmbeddedId public D_PK getId() { return id; } public void setId(D_PK id) { this.id = id; } } ------------------------------------------------------------ The references are as follows - there are no circularity dependencies: A --> A_PK --> D --> D_PK --> C --> B ------------------------------------------------------------ Hibernate throws the following exception: org.hibernate.AnnotationException: Foreign key circularity dependency involving the following tables: D, C, A at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:470) at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:304) at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:762) at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:93) at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:61) at test.DoTest.initTest(DoTest.java:22) ------------------------------------------------------------ When I do any of the following, *no* exception is thrown: - class A_PK: reference "C" instead of "D" (removing "C" from the dependency chain) - class A: move annotation from getter to field declaration "private A_PK id" - class A: replace embedded id "A_PK" by reference to "D" (as in "A_PK") - class A: rename class to "Z" - class B: remove "strategy" parameter from "@Inheritance" annotation - class C: not extending "B" and defining the primary key in "C" - class C: rename class to "Z" - class D: move annotation from getter to field declaration "private D_PK id" - class D: replace embedded id "D_PK" by reference to "C" (as in "D_PK") Attached you'll find a test case.

    Hibernate JIRA | 9 years ago | Sven Woltmann
    org.hibernate.AnnotationException: Foreign key circularity dependency involving the following tables: D, C, A
  3. 0

    Exception in thread "main" org.hibernate.AnnotationException mappedBy reference

    Stack Overflow | 2 years ago
    org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: model.entities.Project.Responsible in model.entities.User.projects
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    "Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements" in hibernate when annotating a ConcurrentHashMap

    Stack Overflow | 5 years ago | Yon
    org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: ConfigurationParameterBag.parameterValues
  6. 0

    mappedBy reference an unknown target entity property error (Object Relational Mapping forum at Coderanch)

    coderanch.com | 7 months ago
    org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: FulltimeEmployee.FlightBenefit in FlightBenefit.FulltimeEmployees

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.hibernate.AnnotationException

      Foreign key circularity dependency involving the following tables: D, C, A

      at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder()
    2. Hibernate
      SchemaExport.<init>
      1. org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:470)
      2. org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:304)
      3. org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:762)
      4. org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:93)
      5. org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:61)
      5 frames
    3. test
      DoTest.initTest
      1. test.DoTest.initTest(DoTest.java:22)
      1 frame