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: Hibernate Mapping ManyToMany Class association not filed
PostPosted: Wed Jun 08, 2011 8:53 am 
Newbie

Joined: Tue May 31, 2011 6:41 am
Posts: 8
Hi everybody.
I need your help.
I have table in that form :
_______________ ░░ _________________░░_____________
│░░░░sfd░░░░░░│░░│sfd_forme_juridique│ │ forme_juridique│
├─────────────░░ ────────────── ░░├────────────
│ -id ░░░░░░░░░│░░ │░░-idSfd░░░░░░░░│░│-id
│ -numAgreement│░░│░-idFormeJuridique│░░│-libelle
│ -nom░░░░░░░░│░░│░░-dateDebut░░░░│░│-enabled
│ -dateAgreement│░ │░░-dateFin░░░░░░│░░└────────
│ -dateRetraitAgr│░░│░░-enabled░░░░░░│
└──────────── ░░└───────────────

with code:
Code:
@Entity
@Table(name = "sfd", catalog = "rol1")
public class Sfd implements java.io.Serializable {

   private Integer id;
   private String numAgreement;
   private String nom;
   private Date dateAgreement;
   private Date dateRetraitAgreement;
   private boolean enabled;
   private Set<FormeJuridique> formeJuridiques=new HashSet<FormeJuridique>();
           
//Getters + setters +constructors

   @ManyToMany(fetch = FetchType.LAZY)
   @Cascade( { CascadeType.SAVE_UPDATE })
   @JoinTable(name = "sfd_forme_juridique", catalog = "econtrol1",
         joinColumns = { @JoinColumn(name = "idSfd", nullable = false) },
         inverseJoinColumns = { @JoinColumn(name = "idFormeJuridique", nullable = false) })
   public Set<FormeJuridique> getFormeJuridiques() {
      return this.formeJuridiques;
   }

   public void setFormeJuridiques(Set<FormeJuridique> formeJuridiques) {
      this.formeJuridiques = formeJuridiques;
   }
}


FormeJuridique
Code:
@Entity
@Table(name = "forme_juridique", catalog = "rol1")
public class FormeJuridique implements java.io.Serializable {
        private Integer id;
   private String libelle;
   private boolean enabled;
   private Set<Sfd> sfds;

//Getters + setters +constructors

   @ManyToMany(fetch = FetchType.LAZY,mappedBy = "formeJuridiques")
   public Set<Sfd> getSfds() {
      return this.sfds;
   }
   public void setSfds(Set<Sfd> sfds) {
      this.sfds = sfds;
   }
}


The class Association
Code:
@Entity
@Table(name = "sfd_forme_juridique", catalog = "rol1")
public class SfdFormeJuridique implements java.io.Serializable {
   private SfdFormeJuridiqueId id;

   public SfdFormeJuridique() {
   }
   public SfdFormeJuridique(SfdFormeJuridiqueId id) {
      this.id = id;
   }
   @EmbeddedId
   @AttributeOverrides({
         @AttributeOverride(name = "idSfd", column = @Column(name = "idSfd", nullable = false)),
         @AttributeOverride(name = "idFormeJuridique", column = @Column(name = "idFormeJuridique", nullable = false)),
         @AttributeOverride(name = "dateDebut", column = @Column(name = "dateDebut", length = 10)),
         @AttributeOverride(name = "dateFin", column = @Column(name = "dateFin", length = 10)),
         @AttributeOverride(name = "enabled", column = @Column(name = "enabled")) })
   public SfdFormeJuridiqueId getId() {
      return this.id;
   }
   public void setId(SfdFormeJuridiqueId id) {
      this.id = id;
   }
}


The probleme when I do
sfd=new Sfd("sfd1");
sfd.addFormeJuridique(new FormeJuridique("fj11");
sfd.save();
the sfd is saved, alse the formeJuridique but the class association was not filled.
Someone can help me please.


Top
 Profile  
 
 Post subject: Re: Hibernate Mapping ManyToMany Class association not filed
PostPosted: Wed Jun 08, 2011 12:53 pm 
Newbie

Joined: Wed Jun 08, 2011 12:50 pm
Posts: 8
Location: Germany
You have to update both sides of the relationship.
This is mentioned in the spec:

Quote:
Note that it is the application that bears responsibility for maintaining the consistency of runtime relationships—for example, for insuring that the “one” and the “many” sides of a bidirectional relationship are consistent with one another when the application updates the relationship at runtime


Top
 Profile  
 
 Post subject: Re: Hibernate Mapping ManyToMany Class association not filed
PostPosted: Wed Jun 08, 2011 2:37 pm 
Newbie

Joined: Tue May 31, 2011 6:41 am
Posts: 8
Hi thanx for your answer.
What do you you want to say exactly i don't understand becaus e my inglish is not verry perform.
Can you illustrate what you aare saying buy un example ???


Top
 Profile  
 
 Post subject: Re: Hibernate Mapping ManyToMany Class association not filed
PostPosted: Wed Jun 08, 2011 3:11 pm 
Newbie

Joined: Wed Jun 08, 2011 12:50 pm
Posts: 8
Location: Germany
For your example this means if you add a FormeJuridique to a sfd, you also have to add this sfd to the FormeJuridique

That is meant by "maintaining the consistency".


Top
 Profile  
 
 Post subject: Re: Hibernate Mapping ManyToMany Class association not filed
PostPosted: Thu Jun 09, 2011 7:48 am 
Newbie

Joined: Tue May 31, 2011 6:41 am
Posts: 8
Yep sorry I think that I have another probleme which update and remove because i have 2 open sessions.
I think that if i resolve this other issue it will work.
thanx


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.