【发布时间】:2018-07-22 06:02:11
【问题描述】:
我有两个实体,分别称为“组”和“通用”。当我尝试使用 Group 的引用在 mySql 中保存通用数据时,它将一条新记录保存到组表中,然后在通用表中使用此记录。这个问题怎么解决???
集团实体:
@Entity
@Table(name = "mdcn_group")
public class Group extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
protected Long id;
private String name;
private int status;
private String comments;
public Group() {
}
public Group(long id){
this.id = id;
}
public Group(long id, String name) {
this.id = id;
this.name = name;
}
// ... getter and setter
通用实体:
@Entity
@Table(name = "generic")
public class Generic extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
protected Long id;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "group_id")
private Group group;
private String name;
private int status;
private String comments;
public Generic(){}
public Generic(long id){
this.id = id;
}
public Generic(long id, String name){
this.id = id;
this.name = name;
}
// ... getter and setter
【问题讨论】:
标签: mysql jpa spring-data-jpa mariadb