JPA中的@Basic(可选= false)vs @Column(nullable = false) [英] @Basic(optional = false) vs @Column(nullable = false) in JPA
问题描述
JPA中 @Basic(可选= false)
和 @Column(nullable = false)
之间的区别是什么持久性?
What's the difference between @Basic(optional = false)
and @Column(nullable = false)
in JPA persistence?
推荐答案
Gordon Yorke(EclipseLink架构委员会成员,TopLink核心技术主管,JPA 2.0专家组成员)写了一个很好的答案关于这个主题所以我没有复述他,而是引用他的回答:
Gordon Yorke (EclipseLink Architecture Committee Member, TopLink Core Technical Lead, JPA 2.0 Expert Group Member) wrote a good answer on this topic so instead of paraphrasing him, I'll quote his answer:
可选
与
之间的差异可以为空
是他们
的评估范围。
'optional
'的定义讨论了属性和
字段值,并建议应该在$ b $内评估这个
特性b运行时。 'nullable
'仅在对数据库列的
引用中。
The difference between
optional
andnullable
is the scope at which they are evaluated. The definition of 'optional
' talks about property and field values and suggests that this feature should be evaluated within the runtime. 'nullable
' is only in reference to database columns.
如果某个实现选择
实现可选
那么那些
属性应该在持久性提供程序的
内存和
在向数据库发送
之前引发的异常,否则当使用
' updatable = false
''可选
'
违规将永远不会被报告。
If an implementation chooses to
implement optional
then those
properties should be evaluated in
memory by the Persistence Provider and
an exception raised before SQL is sent
to the database otherwise when using
'updatable=false
' 'optional
'
violations would never be reported.
这篇关于JPA中的@Basic(可选= false)vs @Column(nullable = false)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!