我正在尝试使用 解析 0 到 1000 范围内的 Year String 值java.time.Year.parse(),但是解析失败java.time.format.DateTimeParseException: Text '999' could not be parsed at index 0。
Year.parse状态的javadoc :
Obtains an instance of Year from a text string such as 2007.
The string must represent a valid year. Years outside the range 0000 to 9999
must be prefixed by the plus or minus symbol.
Run Code Online (Sandbox Code Playgroud)
重现此问题的示例测试:
Obtains an instance of Year from a text string such as 2007.
The string must represent a valid year. …Run Code Online (Sandbox Code Playgroud) 我正在使用 Hibernate 并具有以下 JPA 模型:
@Entity
public class MyEntity {
@Embedded
MyEmbeddable embedded;
}
@Embeddable
public class MyEmbeddable {
@Column
private String name;
@ElementCollection
@Enumerated(EnumType.STRING)
@Size(min = 1)
private Set<MyEnum> usage;
@NotNull
private LocalDate localDate;
}
Run Code Online (Sandbox Code Playgroud)
MyEntity可以包含 MyEmbeddable,但整个 embeddable 应该是可选的。所以我更喜欢MyEntity.embedded当null的所有属性都MyEmbeddable为空或 null 时。
然而,当我从数据库读取这样的实体时,Hibernate 初始化embedded为non-null- ,当实体再次刷新到数据库时,这会导致约束错误。
作为一种解决方法,我必须在刷新/保留之前向该属性编写一些代码null-embedded这对我来说似乎是一个非常糟糕的主意。
我怀疑 ElementCollection 导致了这种初始化行为 - 因为根据 JPA 规范 ElementCollections 始终被初始化empty(不为 null)。
有什么想法/提示可以告诉 Hibernateembedded根本不初始化吗?