-->
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: No primray key generated for oneToMany association
PostPosted: Mon Sep 07, 2009 8:42 am 
Beginner
Beginner

Joined: Mon Jan 10, 2005 7:14 am
Posts: 32
Hi,

I use JPA / Hibernate 3.2.6.GA and I need to model a unidirectional oneToMany association.

Here is the mapping I wrote :

Code:
   @OneToMany(targetEntity=ReponseImpl.class, cascade=CascadeType.REMOVE)
   @JoinTable(
         name="activite_reponse_",
         joinColumns={@JoinColumn(name="activite_fk_")},
         inverseJoinColumns={@JoinColumn(name="reponse_fk_", unique=true)})
   public Collection<Reponse> getReponsesLibres() {
      return reponsesLibres;
   }


From this mapping, I expected to have a primary key in table "activite_reponse_" table composed with "activite_fk_" and "reponse_fk_" fields. But when I run hbm2ddl I have no primary key generated ... It generates the following DDL :

Code:
    create table activite_reponse_ (
        activite_fk_ bigint not null,
        reponse_fk_ bigint not null unique,
        unique (reponse_fk_)
    );

    alter table activite_reponse_
        add index FK3F5785533876861 (activite_fk_),
        add constraint FK3F5785533876861
        foreign key (activite_fk_)
        references activite_ (id_);

    alter table activite_reponse_
        add index FK3F57855664D13F9 (reponse_fk_),
        add constraint FK3F57855664D13F9
        foreign key (reponse_fk_)
        references reponse_ (id_);


Any idea ?

Regards,

Olivier


Top
 Profile  
 
 Post subject: Re: No primray key generated for oneToMany association
PostPosted: Mon Sep 07, 2009 9:46 am 
Beginner
Beginner

Joined: Mon Jan 10, 2005 7:14 am
Posts: 32
I found how to solve my problem : I just had to use Set instead of Collection, the following way, and it works.

Code:
   @OneToMany(targetEntity=ReponseImpl.class, cascade=CascadeType.REMOVE)
   @JoinTable(
         name="activite_reponse_",
         joinColumns={@JoinColumn(name="activite_fk_")},
         inverseJoinColumns={@JoinColumn(name="reponse_fk_", unique=true)})
   public Set<Reponse> getReponsesLibres() {
      return reponsesLibres;
   }


But I must say I don't really understand why ... Is there a reason for this ?


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.