Hi All,
I published this post earlier in >> Projects>> Tools but I found it's something wrong with my annotation not tools. I compiled project to the jar and when I run on some test database I had the same error so it's problem with my annotations. So:
I have problem with @ElementCollection in Hibernate Configurations tab. When I try to see the "Session Factory" node in the tree I have an error:
org.hibernate.MappingException: Repeated column in mapping for collection:. For me annotations in both entities + embeddable class looks OK. Am I right? Or I am missing something? I tested in different variations from google end results always are the same.
Thanks a lot and best wishes,
Jacek
The full stack trace looks like:
Quote:
org.hibernate.MappingException: Repeated column in mapping for collection: org.phibase.database.schema.ReferenceGeneProduct.joinedReferenceGene column: referenceGeneProductID
at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:329)
at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:352)
at org.hibernate.mapping.Collection.validate(Collection.java:309)
at org.hibernate.mapping.Set.validate(Set.java:42)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1197)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1378)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
at org.hibernate.console.ConsoleConfiguration$4.execute(ConsoleConfiguration.java:241)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:72)
at org.hibernate.console.ConsoleConfiguration.buildSessionFactory(ConsoleConfiguration.java:236)
at org.hibernate.eclipse.console.workbench.LazySessionFactoryAdapter.getChildren(LazySessionFactoryAdapter.java:43)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.getChildren(BasicWorkbenchAdapter.java:100)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:106)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:235)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
When I tried to use compiled jar file on test application I had the stack trace:
Quote:
... not important Spring's complains ...
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: phibase.schema] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:911)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 47 more
Caused by: org.hibernate.MappingException: Repeated column in mapping for collection: org.phibase.database.schema.ReferenceGeneProduct.joinedReferenceGene column: referenceGeneProductID
at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:341)
at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:364)
at org.hibernate.mapping.Collection.validate(Collection.java:321)
at org.hibernate.mapping.Set.validate(Set.java:42)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1336)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1835)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902)
... 52 more
The code for particular tables looks like:
Entity 1
Code:
@Entity
@Table(name="ReferencePhysicalGene")
public class ReferencePhysicalGene implements Serializable {
....
....
@ElementCollection(fetch=FetchType.LAZY)
@CollectionTable(name="ReferencePhysicalGeneEncodesReferenceGeneProduct",
joinColumns= @JoinColumn(name="referenceGeneID"))
public Set<JoinReferenceGeneReferenceProduct> getJoinedGeneProducts() {
return joinedGeneProducts;
}
}
Entity 2
Code:
@Entity
@Table(name="ReferenceGeneProduct")
public class ReferenceGeneProduct implements Serializable {
...
...
@ElementCollection(fetch=FetchType.EAGER, targetClass=JoinReferenceGeneReferenceProduct.class)
@JoinTable(name="ReferencePhysicalGeneEncodesReferenceGeneProduct",
joinColumns= @JoinColumn(name="referenceGeneProductID", nullable=false))
public Set<JoinReferenceGeneReferenceProduct> getJoinedReferenceGene() {
return joinedReferenceGene;
}
}
The join table @Embeddable class is:
Code:
@Embeddable
public class JoinReferenceGeneReferenceProduct implements
Serializable {
....
@Column(name="referenceGeneProductID", nullable=false)
public Long getReferenceGeneProductID() {
return referenceGeneProductID;
}
...
@Column(name="referenceGeneID", nullable=false)
public Long getReferenceGeneID() {
return referenceGeneID;
}
...
}