相关实体将被保持为空
我是jpa和hibernate的新手,我试图坚持一个与两个实体有2个关系的bean,因为我这样做了我试图保存的实体被保存但相关实体不存在,他们留下来空第一课
@Entity @Table(name = "MODIFICATION") public class ModificationBE extends AbstractBE implements Serializable { /** * */ private static final long serialVersionUID = 5862456626257704084L; @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "modification_seq") @SequenceGenerator(name = "modification_seq", sequenceName = "modification_sequence", allocationSize = 1) @Column(name = "ID", unique = true, nullable = false) private Long idModification; @Relation(RelationType.ENTITY) @OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER, orphanRemoval = false) @JoinColumn(name = "ID_Profils") private List profils; @Relation(RelationType.ENTITY) @OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER) @JoinColumn(name = "ID_Utiisateur") private UtilisateurBE user;
第二课
@Entity @Table(name = "Utilisateur") public class UtilisateurBE extends AbstractBE implements Serializable { /** * */ private static final long serialVersionUID = 5192421474902029299L; @Id @Column(name = "ID", unique = true, nullable = false) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_seq") @SequenceGenerator(name = "user_seq", sequenceName = "user_sequence", allocationSize = 1) private Long idUtilisateur; @Column(name = "nom") private String nom; @Column(name = "prenom") private String prenom; @Column(name = "email") private String email; @Enumerated(EnumType.STRING) @Column(name = "type") TypeUtilisateur typeUser; @OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY) private ModificationBE modification;
第三类/实体
@Entity @Table(name = "PROFIL") public class ProfilBE extends AbstractBE implements Serializable { /** * */ private static final long serialVersionUID = -4017244348063720915L; @Id @Column(name = "ID", unique = true, nullable = false) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "profil_seq") @SequenceGenerator(name = "profil_seq", sequenceName = "profil_sequence", allocationSize = 1) private Long idProfil; @Column(name = "nom") private String nom; @Column(name = "prenom") private String prenom; @Column(name = "email") private String email; @Enumerated(EnumType.STRING) @Column(name = "type") private TypeProfil typeProfil; @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.DETACH) @JoinColumn(name = "ID_Groups") private List groups; @Column(name = "status") private boolean status;
我试图发布这个
{ "idModification": 1, "profils": [ { "idProfil": 1, "nom": "toto", "prenom": "ElGrande", "email": "elGrande.toto@vero.com", "typeProfil": "ASSOCIE", "groups": [ { "id": 2936, "name": "Suivi Performance Entrepôt", "centrale": "NORD-OUEST", "specGroupe": null, "privilege": "CPI et développeur" }, { "id": 3008, "name": "SIDO", "centrale": "NORD-OUEST", "specGroupe": "Appro", "privilege": "Expert" } ], "status": true }, { "idProfil": 1, "nom": "tata", "prenom": "ElGrande", "email": "elGrande.tata@vero.com", "typeProfil": "PDV", "groups": [ { "name": "SIDO", "idGroup": 1 }, { "name": "SIDE", "idGroup": 2 } ], "status": "true" } ], "user": { "nom": "Lemcirdi", "prenom": "Anas", "email": "anas.lemcirdi@haha.com", "typeUser": "SID", "id": "1" } }
但是这个
{ "idModification": 1, "profils": null, "user": null }
什么被保存到我的数据库,我没有得到任何错误,所以它必须是一个映射错误。 我该如何解决它。
链接地址: http://www.djcxy.com/p/90899.html