Bonjour,

J'ai 2 Entity Bean :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
@Entity
public class Adresse implements Serializable {
    private static final long serialVersionUID = 1L;
 
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
 
    private String ville;
 
    @JoinColumn(name = "id_client", referencedColumnName = "id")
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Client idClient;
 
// accesseurs
... et :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
@Entity
public class Client implements Serializable {
    private static final long serialVersionUID = 1L;
 
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
 
    private String nom;
 
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idClient", fetch = FetchType.EAGER)
    private List<Adresse> adresseCollection;
 
// accesseurs
Et la commande via un Session Bean :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
public void addClient(Client client) throws Exception {
 
// client contient la List<Adresse> adresses initialisée
        em.persist(client);
 
    }
Et la belle exception suivante à l'exécution :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
 javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: entity.Adresse.idClient
Comment insérer les valeurs des 2 tables en même temps car il y a une relation 1,1 to 1,n ?

A+