Hi All,
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. Might it be an error in Hibernate Tools?
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)
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;
}
...
}