-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Foreign key circularity dependency ??
PostPosted: Wed Feb 06, 2008 5:37 am 
Newbie

Joined: Wed Feb 06, 2008 5:12 am
Posts: 4
Hibernate version:Hibernate Core, 3.2.5.ga, Hibernate Annotations 3.3.0 GA, Hibernate EntityManager 3.3.1 GA

Hi, i'm facing a serious problem with entities. An exception is raised saying there is circularity where there isn't !

Full stack trace of any exception that occurs:
Quote:
javax.persistence.PersistenceException: org.hibernate.AnnotationException: Foreign key circularity dependency involving the following tables: Droitacces, Benefserv, Acces
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:258)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at test.DoTest.initTest(DoTest.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.AnnotationException: Foreign key circularity dependency involving the following tables: Droitacces, Benefserv, Acces
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:458)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:295)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1269)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:150)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:888)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:186)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:246)
... 24 more



Here is the simplified code:

Code:
@Entity
public class Acces
{
    @Id
    private BigInteger idpk;

    @ManyToOne
    private Droitacces idpkdracc;
}
Code:
@Entity
public class Droitacces  {
    @Id
    private BigInteger idpk;

    @ManyToOne
    private Benefserv idpkbenef;

    @OneToMany(mappedBy = "idpkdracc")
    private Collection<Acces> accesCollection;
}
Code:
@Entity
public class Benefserv  {
    @Id
    private BigInteger idpk;

    @ManyToOne
    private Service idpkser;
   
    @OneToMany(mappedBy = "idpkbenef")
    private Collection<Droitacces> droitaccesCollection;
}
Code:
@Entity
public class Service {
    @Id
    private BigInteger idpk;

    @OneToMany(mappedBy = "idpkser")
    private Collection<Benefserv> benefservCollection;
}


As you can see, there is no circularity. It can be represented like this :
Quote:
Acces -> Droitacces -> Benefserv -> Service

What is strange, is if i rename for example "idpkdracc" (which is unique) to "fkdracc" , it works ! I tried also to rename "Acces" to "A" and "Droitacces" to "B", it does work...

Anyone got an idea ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 6:44 am 
Beginner
Beginner

Joined: Thu Jun 07, 2007 2:38 am
Posts: 28
Location: Italy, Rome
It looks like your circularity is
(1) Benefserv -> Service
Code:
@ManyToOne
    private Service idpkser;

(2) Service -> Benefserv
Code:
  @OneToMany(mappedBy = "idpkser")
    private Collection<Benefserv> benefservCollection;


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 9:05 am 
Newbie

Joined: Wed Feb 06, 2008 5:12 am
Posts: 4
erikvaningen wrote:
It looks like your circularity is
(1) Benefserv -> Service
Code:
@ManyToOne
    private Service idpkser;

(2) Service -> Benefserv
Code:
  @OneToMany(mappedBy = "idpkser")
    private Collection<Benefserv> benefservCollection;


I don't think so, it's a bidirectionnal relation like in http://www.hibernate.org/hib_docs/annot ... ml#d0e1352 . Also those entity bean are auto-generated with netbean from a perfectly working DB2 database, I just removed extra code to simplify.

Edit I try without @OneToMany, and it also does not work (but it's code is more simple)

Code:
@Entity
public class Acces
{
    @Id
    private BigInteger idpk;

    @ManyToOne
    private Droitacces idpkdracc;
}
Code:
@Entity
public class Droitacces  {
    @Id
    private BigInteger idpk;

    @ManyToOne
    private Benefserv idpkbenef;
}
Code:
@Entity
public class Benefserv  {
    @Id
    private BigInteger idpk;

    @ManyToOne
    private Service idpkser;
}
Code:
@Entity
public class Service {
    @Id
    private BigInteger idpk;
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 9:46 am 
Newbie

Joined: Wed Feb 06, 2008 5:12 am
Posts: 4
I'am 99% sure that it's a Hibernate bug, because the same code running with the Toplink JPA work perfectly...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 10:18 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Yes it looks like a bug. Can you post the code of your simple test in JIRA.

Note that Toplink cannot have this kind of bug as they do not go as far as Hibernate goes in term of defaults and exotic mappings. They will have too in the next Java Persistence version possibly.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 10:49 am 
Beginner
Beginner

Joined: Thu Jun 07, 2007 2:38 am
Posts: 28
Location: Italy, Rome
I would like to add this: Your assumption that it is bidirectional is not correct because the relation is always ManyToOne, unidirectional : Acces -> DroitAcces ->BenefSerf -> Service


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 3:33 pm 
Newbie

Joined: Wed Feb 06, 2008 5:12 am
Posts: 4
http://opensource.atlassian.com/project ... se/ANN-694


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.