我有以下实体类:
@Entity
@Table(name = "employee")
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id;
@NotNull
@NaturalId
private String tagId;
@NotNull
@Size(max = 255, message = "Employee name can not be longer than 255 character")
private String name;
@Type(type = "yes_no")
private boolean isInside;
@PastOrPresent(message = "Last RFID timestamp can not be in the future")
private ZonedDateTime lastSwipe;
//Constuctors, getters and setters
}
具有以下优点:
public interface EmployeeRepository extends JpaRepository {
Optional findByTagId(String tagId);
}
假设我在数据库中有一个员工,TagID为“SomeStringForID”。
现在,如果我使用
findByTagId
方法,其中TagID等于“SomeStringForID”,例如,在数据库中找到员工。
. 如果我试图用tagid“someStringForID”保存另一个员工,我会得到一个异常,这要感谢
@NaturalId
注释。
知道是什么导致了这种行为吗?Spring命名的查询有IgnoreCase选项,所以我很确定这不应该是默认行为。我也检查了我的一个老项目,在哪里我发现了同样的行为让我惊讶。我试过JDK8和11版本。