Bonjour,
j'ai deux entités dépendantes dépendantes l'une de l'autre: DooGooderEntity et DoogooderAddressEntity. Cette relation est une relation user, address.
Lorsque je persiste le user (avec une adresse), tout fonctionne, le user et l'adresse sont sauvés dans la bdd.
Mais si j'essai de persister l'adresse, cela ne marche pas complètement. La clé étrangère user n'est jamais renseigné pour le user dans la table correspondante. Quel est le problème? Une petite idée?
Ci-joint le code de mes deux classes?
DooGooderEntity
DoogooderAddressEntity :
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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 @Entity @Table(name = DooGooderEntity.TABLE_NAME, uniqueConstraints = { @UniqueConstraint(columnNames = { "id", "memberId" }) }) public class DooGooderEntity { public static final String TABLE_NAME = "tbl_doogooder"; public static final String FIELD_DOOGOODER_ID = "id"; @Id @GeneratedValue @Column private long id; @Column(length = 50) private String firstname; @Column(length = 50) @NotEmpty private String name; @Column(length = 100) // @NotEmpty private String email; @Column(length = 20) // @NotEmpty private String login; @Column(length = 20) // @NotEmpty private String password; @Column(length = 20) // @NotEmpty private String memberId; // @NotEmpty private java.sql.Date birthdate; // only store date @Column(length = 15) // @NotEmpty private String phone; @Column(length = 15) private String mobile; @Column(length = 5) private String gender; @Column private java.sql.Date premiumTill; @JoinColumn(name = "userRoleid") @OneToOne private UserRoleEntity userRole; @JoinColumn(name = "doogooderStatusid") @OneToOne private DooGooderStatus doogooderStatus;
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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 @Entity @Table(name = DoogooderAddressEntity.TABLE_NAME) public class DoogooderAddressEntity { public static final String TABLE_NAME = "tbl_doogooder_address"; public static final String DOOGOODER_FIELD_NAME = "doogooder"; @Id @GeneratedValue @Column(length = 10, name = "id") private long addId; @Column(length = 100) private String street; @Column(length = 100) private String street2; @Column(length = 10) private String postCode; @Column(length = 60) private String city; @OneToOne(cascade = CascadeType.ALL) @JoinColumn(name = "doogooderId", updatable = false, nullable = false) private DooGooderEntity doogooder; @OneToOne(mappedBy = DoogooderGeoLocationEntity.FIELD_ADDRESS_NAME, cascade = CascadeType.ALL) @JoinColumn(name = "doogooderGeoLocationId") private DoogooderGeoLocationEntity geoLocation; @Column(length = 2) private String countryIsoCode; ...
Partager