-->
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.  [ 2 posts ] 
Author Message
 Post subject: @ElementCollection Repeated column in mapping for collection
PostPosted: Mon Jan 24, 2011 6:15 pm 
Newbie

Joined: Tue Jun 22, 2010 11:26 am
Posts: 9
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;
   }

...
}



Top
 Profile  
 
 Post subject: Re: @ElementCollection Repeated column in mapping for collection
PostPosted: Mon Jan 24, 2011 11:53 pm 
Newbie

Joined: Tue Jun 22, 2010 11:26 am
Posts: 9
Hi,

I found finally a solution. The error message reason was that Embeddable class contained variables which were foreign
keys. It looks Than java itself cares to create foreign keys in the join tables. But also when I created an empty class, without any variables than In had another error. So It looks only replacement for many-to-many is one-to-many and many-to-one.

Regards,
Jacek


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.