-->
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: Collection of elements must not have mappedBy or associat...
PostPosted: Mon Dec 05, 2005 10:09 pm 
Beginner
Beginner

Joined: Tue Dec 09, 2003 5:59 pm
Posts: 25
Location: Los Angeles
I'm getting the error message "Collection of elements must not have mappedBy or association reference an unmapped class" from Hibernate when I try to initialize a session. It seems like the mapping that I'm trying to use should be possible. My hibernate.cfg.xml has mapping entries for all 3 classes listed below in it. Regardless of what the problem is here, the error message certainly seems to be wrong, since there are no unmapped classes involved here.

Hibernate version: 3.1rc1
Hibernate Annotations version: 3.1b6

Mapping documents:
Code:
A.java:
@Entity
@Table(name="A")
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class A extends SuperA {
  private Set<B> _bs = new HashSet<B>();
  @OneToMany(mappedBy="a")
  public Set<B> getBs() {
    return _bs;
  }
}

B.java:
@EmbeddableSuperclass
public abstract class B extends SuperB {
  private A _a;
  @ManyToOne
  @JoinColumn(name="AID")
  public A getA() {
    return _a;
  }
}

C.java:
@Entity
@Table(name="C")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE,
  discriminatorType=DiscriminatorType.STRING,
  discriminatorValue="C"
)
public class C extends B {
...


Full stack trace of any exception that occurs:
Collection of elements must not have mappedBy or association reference an unmapped class: A.bs
org.hibernate.AnnotationException: Collection of elements must not have mappedBy or association reference an unmapped class: A.bs
at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:689)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:407)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:368)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:35)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1023)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:218)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1138)
at com.adapt.clcm.storage.StorageService.getSessionFactory(StorageService.java:55)
at com.adapt.clcm.storage.StorageService.getSession(StorageService.java:42)
at com.adapt.clcm.model.ModelTest.setUp(ModelTest.java:20)
at com.adapt.clcm.core.test.BaseTestCase.runBare(BaseTestCase.java:40)

Name and version of the database you are using: Hypersonic 1.8.0.1

Debug level Hibernate log excerpt:
18:04:40 DEBUG CollectionSecondPass : Second pass for collection: A.bs
18:04:40 DEBUG CollectionBinder : Binding a collection of element: A.bs


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 12:53 pm 
Beginner
Beginner

Joined: Tue Dec 09, 2003 5:59 pm
Posts: 25
Location: Los Angeles
I switched the association around so that A is now the managing end, and Hibernate stopped complaining. It appears that Hibernate can't handle an abstract class being on the managing end of an assocation. Does this sound right?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 6:00 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You're right is should have been
Collection of elements must not have mappedBy or association reference an unmapped entity

B is not an entity

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 6:02 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hibernate supports abstract classes

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 6:04 pm 
Beginner
Beginner

Joined: Tue Dec 09, 2003 5:59 pm
Posts: 25
Location: Los Angeles
Thanks for the reply emmanuel, but I don't really understand it. Are you saying that Hibernate does allow an abstract class to be on the managing end of an assocation? If so, does this mean that the example that I provided should work, or does it look like I'm doing something wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 2:39 pm 
Beginner
Beginner

Joined: Tue Dec 09, 2003 5:59 pm
Posts: 25
Location: Los Angeles
Upon closer inspection, this isn't working after all. When I changed the managing end of the association, Hibernate stopped complaining, but that doesn't mean it's working right. Hibernate now thinks that A has a separate Set of Bs. It doesn't figure out that A's B's and B's A are opposite ends of the same association. Are polymorphic associations even supported at all in Hibernate annotations?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 1:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
javajedi wrote:
Are polymorphic associations even supported at all in Hibernate annotations?

Of course, like I said B is not an entity
Code:
@EmbeddableSuperclass
public abstract class B

an embedded superclass is not an entity

_________________
Emmanuel


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.