<bdo id='s7xjU'></bdo><ul id='s7xjU'></ul>

  1. <small id='s7xjU'></small><noframes id='s7xjU'>

    <i id='s7xjU'><tr id='s7xjU'><dt id='s7xjU'><q id='s7xjU'><span id='s7xjU'><b id='s7xjU'><form id='s7xjU'><ins id='s7xjU'></ins><ul id='s7xjU'></ul><sub id='s7xjU'></sub></form><legend id='s7xjU'></legend><bdo id='s7xjU'><pre id='s7xjU'><center id='s7xjU'></center></pre></bdo></b><th id='s7xjU'></th></span></q></dt></tr></i><div id='s7xjU'><tfoot id='s7xjU'></tfoot><dl id='s7xjU'><fieldset id='s7xjU'></fieldset></dl></div>
  2. <tfoot id='s7xjU'></tfoot>

    1. <legend id='s7xjU'><style id='s7xjU'><dir id='s7xjU'><q id='s7xjU'></q></dir></style></legend>

      @OneToOne(optional=false) 和 @JoinColumn(nullable=false) 一起

      时间:2023-09-28
          • <bdo id='d4V2k'></bdo><ul id='d4V2k'></ul>

              <i id='d4V2k'><tr id='d4V2k'><dt id='d4V2k'><q id='d4V2k'><span id='d4V2k'><b id='d4V2k'><form id='d4V2k'><ins id='d4V2k'></ins><ul id='d4V2k'></ul><sub id='d4V2k'></sub></form><legend id='d4V2k'></legend><bdo id='d4V2k'><pre id='d4V2k'><center id='d4V2k'></center></pre></bdo></b><th id='d4V2k'></th></span></q></dt></tr></i><div id='d4V2k'><tfoot id='d4V2k'></tfoot><dl id='d4V2k'><fieldset id='d4V2k'></fieldset></dl></div>

                  <tbody id='d4V2k'></tbody>

                <small id='d4V2k'></small><noframes id='d4V2k'>

              1. <tfoot id='d4V2k'></tfoot>

                <legend id='d4V2k'><style id='d4V2k'><dir id='d4V2k'><q id='d4V2k'></q></dir></style></legend>
                本文介绍了@OneToOne(optional=false) 和 @JoinColumn(nullable=false) 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我在 JPA 2.0 FR Specification, 11.1.37 中遇到了这个示例.OneToOne 注释,第 403 页:

                I've bumped into this example in JPA 2.0 FR Specification, 11.1.37. OneToOne Annotation, page 403:

                @OneToOne(optional=false)
                @JoinColumn(name="CUSTREC_ID", unique=true, nullable=false, updatable=false)
                public CustomerRecord getCustomerRecord() { return customerRecord; }
                

                有什么理由我应该放 @OneToOne(optional=false) 并同时放 @JoinColumn(... nullable=false)?

                Is there any reason that I should put @OneToOne(optional=false) and at that same time put @JoinColumn(... nullable=false)?

                这两个声明不一样吗?其中一个不是多余的吗?
                它们都用于 DDL 模式生成吗?

                Aren't these two declarations the same? Isn't one of them redundant?
                Are both of them used in DDL schema generation?

                推荐答案

                正式地 optional=false 是 JPA 实现的运行时指令,而 nullable=false 是DDL 生成器的指令.所以它们并不是严格冗余的.

                Formally optional=false is a runtime instruction to the JPA implementation, and nullable=false is an instruction to the DDL generator. So they are not strictly redundant.

                当涉及实体继承时,差异可能会变得很大.如果特定映射仅存在于子类上,并且您有单个表每层次结构的策略,那么 OneToOne 映射可能在包含该映射的特定子类上是 optional=false.但是,实际的连接列不能不为空,否则共享表的其他子类不能插入!

                The difference can become significant when there is entity inheritance involved. If a particular mapping exists only on a subclass, and you have single table table per-hierarchy strategy, then the OneToOne mapping may be optional=false on the particular subclass that contains the mapping. However, the actual join column cannot be made not-null, since then other sub classes that share the table can't be inserted!

                在实践中,不同提供者的不同版本可能会或可能不会在任何时候解释任何一个,请注意.

                In practice different versions of different providers may or may not interpret either one at either time, caveat emptor.

                这篇关于@OneToOne(optional=false) 和 @JoinColumn(nullable=false) 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何对 Spring MVC 注释控制器进行单元测试? 下一篇:@Component 和 @Named 都用于同一个 bean 类

                相关文章

                最新文章

                  • <bdo id='20sut'></bdo><ul id='20sut'></ul>
                  <legend id='20sut'><style id='20sut'><dir id='20sut'><q id='20sut'></q></dir></style></legend>

                    <small id='20sut'></small><noframes id='20sut'>

                    <tfoot id='20sut'></tfoot>
                  1. <i id='20sut'><tr id='20sut'><dt id='20sut'><q id='20sut'><span id='20sut'><b id='20sut'><form id='20sut'><ins id='20sut'></ins><ul id='20sut'></ul><sub id='20sut'></sub></form><legend id='20sut'></legend><bdo id='20sut'><pre id='20sut'><center id='20sut'></center></pre></bdo></b><th id='20sut'></th></span></q></dt></tr></i><div id='20sut'><tfoot id='20sut'></tfoot><dl id='20sut'><fieldset id='20sut'></fieldset></dl></div>