-->
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.  [ 5 posts ] 
Author Message
 Post subject: Annotations: composite pk with two manytoone not working
PostPosted: Mon Apr 11, 2005 3:09 pm 
Beginner
Beginner

Joined: Mon Mar 14, 2005 4:16 pm
Posts: 27
Hi,

I've created an entity with a class as ebeddedId. This composite id has two columns associated in a manytoone way with other entities. When I run my test class I get this exception:

Code:
Exception in thread "main" java.lang.ExceptionInInitializerError
...
Caused by: java.util.NoSuchElementException
   at java.util.AbstractList$Itr.next(AbstractList.java:427)
   at org.hibernate.util.JoinedIterator.next(JoinedIterator.java:53)
   at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1105)
   at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:699)
   at org.hibernate.cfg.AnnotationBinder.processElementsOfAClass(AnnotationBinder.java:573)
   at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:436)
   at org.hibernate.cfg.AnnotationConfiguration.addAnnotatedClass(AnnotationConfiguration.java:94)
   at com.ebiointel.bioexedra.ebiosnp.data.service.ConfigurationFactory.newConfiguration(ConfigurationFactory.java:38)
   at com.ebiointel.bioexedra.ebiosnp.data.util.EbioSnpHibernateUtil.<clinit>(EbioSnpHibernateUtil.java:49)
   ... 1 more


This not happens when there is only one of the two manytoone associations of the PK class. It does not depend on which association I use. I think this coult be a bug, because it occurs always when there is more than one manytoone association.

Any ideas?

Bruno


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 6:39 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 7:39 am 
Beginner
Beginner

Joined: Mon Mar 14, 2005 4:16 pm
Posts: 27
Ok, I use 3 entities:

GenDist
- PK gen_dist_id

Gen
- PK gen_id

GenFreq
- PK gen_dist_id (foreign key of GenDist)
- PK gen_id (foreign key of Gen)

GenFreq has a composite pk, implemented in the class GenFreqPK. This is the code of the entities and the class, after removing some properties to improve readibility:

Code:
@Entity
public class GenDist implements Serializable {

    private long id;

   @Id(generate = GeneratorType.SEQUENCE, generator = "gen_dist_seq")
    @Column(name = "gen_dist_id")
    public long getId() {
        return id;
    }

    public long setId() {
        return id;
    }

  // more properties here

}


Code:
@Entity
public class Gen implements Serializable {

   private long id;

    @Id(generate=GeneratorType.SEQUENCE, generator="GEN_SEQ")
    @Column(name="gen_id")
    public long getId() {
        return id;
    }
   
    public void setId(long id) {
        this.id = id;
    }

   // other properties here

}


Code:
@Entity
public class GenFreq implements Serializable {

   private GenFreqPK genFreqPK;

   @EmbeddedId
    public GenGreqPK getId() {
        return genFreqPK;
    }

    // other properties here

}


Code:
@Embeddable
public class GenFreqPK  implements Serializable{

@ManyToOne(targetEntity="GenDist")
   @JoinColumn(name="gen_dist_id")
   public GenDist getGenDist() {
      return genDis;
   }

   public void setGenDist(GenDist genDist)      {
      this.genDist = genDist;
   }

@ManyToOne(targetEntity="Gen")
    @JoinColumn(name = "gen_id")
   public Gen getGen() {
      return gen;
   }

   public void setGen(Gen gen) {
      this.gen = gen;
   }

}


If there is only one of the @ManyToOne in the GenFreqPK class everything works, but when I use both, the exception is thrown. It does not depend in the @ManyToOne I choose. It always work as expected with one, but no two...

Thanks,

Bruno


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 8:35 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It was not supposed to work properly even for 1, actually. Can you wrap it up in a runnable testcase and post it to JIRA, I'll check it.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 11:45 am 
Beginner
Beginner

Joined: Mon Mar 14, 2005 4:16 pm
Posts: 27
Created JIRA ticket HHH-336 with test case (http://opensource.atlassian.com/projects/hibernate/browse/HHH-336)


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