在Hibernate中将另一个对象插入数据库之前,如何检查同一对象是否存在?

时间:2019-03-08 16:51:56

标签: java hibernate validation

Team.java

@Entity
@Table(name = "team")
public class Team {

@Id
@Column(name = "team_id")
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;

@NotNull
@NotEmpty
@Size(max = 30)
private String leadName;

@NotNull
@NotEmpty
@Email(message = "email must be valid")
private String leadEmail;

@NotNull
@NotEmpty
@Size(max = 30)
private String teamName;

@ManyToOne
@JoinColumn(name = "city_id")
private City city;

@OneToMany( cascade = CascadeType.ALL)
@JoinColumn(name = "team_id")
private List<Idea> ideas;

@NotNull
@NotEmpty
private String organization;

...
}

这是JAVA Hibernate类(Spring Boot),并且存在TeamRepository类。插入之前,我想检查JPA信息库(TeamRepository)中是否存在相同的条目。休眠注释怎么办?可能吗?

0 个答案:

没有答案