<tfoot id='MKNxe'></tfoot>

        <bdo id='MKNxe'></bdo><ul id='MKNxe'></ul>
    1. <legend id='MKNxe'><style id='MKNxe'><dir id='MKNxe'><q id='MKNxe'></q></dir></style></legend>

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

    4. 使用 JPA 时,@Entity 和 @Table 中的 name 参数有什么

      时间:2023-09-28
      1. <tfoot id='gsu8C'></tfoot>

            <legend id='gsu8C'><style id='gsu8C'><dir id='gsu8C'><q id='gsu8C'></q></dir></style></legend>

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

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

                <tbody id='gsu8C'></tbody>
                <bdo id='gsu8C'></bdo><ul id='gsu8C'></ul>
                本文介绍了使用 JPA 时,@Entity 和 @Table 中的 name 参数有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在使用 JPA2,并且 @Entity@Table 都有一个 name 属性,例如.g.:

                I'm using JPA2 and both @Entity and @Table have a name attribute, e. g.:

                @Entity(name="Foo")
                @Table (name="Bar")
                class Baz
                

                我应该使用什么,哪些是可选的?

                What should I use, which ones are optional?

                在我的具体情况下,我有一个类 User 和一个类 Group,它们有额外的要求(据我所知),因为它们是 SQL 中的保留字.

                In my specific case I have a class User and a class Group, which have additional requirements (as far as I understand) because they are reserved words in SQL.

                一个可行的解决方案是什么样的?在编写查询时我将使用哪个名称来引用实体?

                How would a working solution look like and with which name would I refer to the entity when writing queries?

                更新:我将 name="GROUPS" 添加到 Group 的两个注释中,并为 User 做了同样的事情,但现在我明白了错误:

                Update: I added name="GROUPS" to both annotations in Group and did the same for User, but now I get this error:

                Exception Description: The table [USERS] is not present in this descriptor.
                Descriptor: RelationalDescriptor(example.Group --> [DatabaseTable(GROUPS)])
                

                还有这个错误

                Internal Exception: java.sql.SQLException: Table not found in statement [SELECT ID, MAXIMUMROLE, MEMBERSHIPS_ID FROM USERS]
                

                推荐答案

                @Table 是可选的.将 POJO 类注释为实体时需要 @Entity,但 name 属性不是必需的.

                @Table is optional. @Entity is needed for annotating a POJO class as an entity, but the name attribute is not mandatory.

                如果你有课

                 @Entity
                 class MyEntity {}
                

                将创建一个名为MyEntity"的表,实体名称为MyEntity.您的 JPQL 查询将是:

                A table with name "MyEntity" will be created and the Entity name will be MyEntity. Your JPQL query would be:

                 select * from MyEntity
                

                在 JPQL 中,您始终使用实体名称,默认情况下它是类名称.

                In JPQL you always use the Entity name and by default it is the class name.

                如果你有课

                 @Entity(name="MyEntityName")
                 @Table(name="MyEntityTableName")
                 class MyEntity {}
                

                然后创建名称为 MyEntityTableName 的表,实体名称为 MyEntityName.

                then a table with name MyEntityTableName is created and the entity name is MyEntityName.

                您的 JPQL 查询将是:

                Your JPQL query would be :

                 select * from MyEntityName
                

                这篇关于使用 JPA 时,@Entity 和 @Table 中的 name 参数有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Android Studio 中@override 的含义 下一篇:反对注解的论点

                相关文章

                最新文章

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

              • <tfoot id='AOl3d'></tfoot>

                  <legend id='AOl3d'><style id='AOl3d'><dir id='AOl3d'><q id='AOl3d'></q></dir></style></legend>

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