users@glassfish.java.net

JPA : Trouble with a ManyToMany

From: <glassfish_at_javadesktop.org>
Date: Mon, 05 Apr 2010 02:48:43 PDT

Hi everyone !

I got a problem with a ManyToMany relationship :

          
Acteur * ------------ * CD
                      

[u]In my class Acteur :[/u]

@Entity
public class Acteur extends Personne{

    @ManyToMany
    @JoinTable(name = "CD_ACTEUR", joinColumns = @JoinColumn(name = "acteur_fk", columnDefinition="BIGINT", referencedColumnName="ID"), inverseJoinColumns = @JoinColumn(name = "cd_fk", columnDefinition="BIGINT", referencedColumnName="ID"))
    private List<CD> CDs;
....

[u]In my class CD :[/u]

@Entity
public class CD {
    @ManyToMany(mappedBy="CDs")
    private List <Acteur> acteurs;
...

So a association table is created : CD_ACTEUR (specified in the class Acteur)

But when i persist a object Acteur (which have no CD) and after an object CD (which have the Acteur previously created) there is a problem !
Every attributes are well stored in the 2 tables CD and ACTEUR but the table CD_ACTEUR is always empty !
Normally it has to be filled with the 2 primaries key ??
[Message sent by forum member 'manta7']

http://forums.java.net/jive/thread.jspa?messageID=395310