Hibernate version: the latest GA releases, Hibernate Core 3.2.5.ga, Hibernate Annotations 3.3.0 GA, Hibernate EntityManager 3.3.1 GA. (The problem was repeated also under the Hibernate Core 3.2.2)
I encountered the same issue as
ANN-376, as far as I can tell. In the bug it says it's a duplicate but doesn't mention what it is a duplicate of. A search on Google and related forums only brought this bug, and I couldn't find the supposed duplicate, or any other documentation of this error.
In my case, the problem did not occur at first, the hibernate was working fine until we added a ManyToOne relation (which is mapped in the reverse direction). So long as the relation was based on a join column alone, it worked fine:
Code:
@Entity
@Table(name = "X")
@Inheritance(strategy = InheritanceType.JOINED)
Class X extends R {
@ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
@JoinColumn(name = "XrelToY")
public Y getY() {..}
}
@Entity
@Table(name = "Y")
@Inheritance(strategy = InheritanceType.JOINED)
Class Y extends R {
@OneToMany(mappedBy = "y")
public Set<X> getAllX()
{..}
}
But once we changed the mapping to a join table (as follows) we got the error (below).
Code:
@Entity
@Table(name = "X")
@Inheritance(strategy = InheritanceType.JOINED)
Class X extends R {
@ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
@JoinTable(name = "XrelationToY", joinColumns = @JoinColumn(name = "X_id"), inverseJoinColumns = @JoinColumn(name = "Y_id"))
public Y getY() {..}
}
@Entity
@Table(name = "Y")
@Inheritance(strategy = InheritanceType.JOINED)
Class Y extends R {
@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
@JoinTable(name = "XrelationToY", joinColumns = @JoinColumn(name = "X_id"), inverseJoinColumns = @JoinColumn(name = "Y_id"))
public Set<X> getAllX()
{..}
}
We also tried several variations (having the inverse relation mappedBy, switching the direction of the join and inverse columns) - all with the same result.
At first we thought there may be a case-sensitivity issue but lowercasing all tablenames ruled that out. The same error kept coming back.
Full stack trace of any exception that occurs:The generated SQL (show_sql=true):Debug level Hibernate log excerpt:Code:
4157 [main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Identity insert: insert into R (A, B, C, D) values (?, ?, ?, ?)
4204 [main] ERROR org.hibernate.AssertionFailure - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: Table XrelationToY not found
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.getTableId(JoinedSubclassEntityPersister.java:458)
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:237)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:58)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:730)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at com.dataessence.sandbox.domain.financial.vocabulary.TestVocabulary.testEntityManager(TestVocabulary.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
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)
Name and version of the database you are using: MySQL 5.0.22
Thanks so much for your time, hope it's clear.
For now we are backing off to a join column, but it seems to me that the bug mentioned above is still in existence.