JPA 数据库分隔符

发布于 2024-11-25 12:40:24 字数 1385 浏览 0 评论 0原文

我有两个实体类,称为“用户”和“组”,这两个保留字都需要分隔,以便数据库将它们接受为表。用: 注释实体

@Table(name = "\"USER\"")

可以解决问题,但我读到 EclipseLink 允许您指定一个自动分隔名称的全局变量。根据 http://dev.eclipse.org/mhonarc/lists/eclipselink -users/msg03434.html,您需要在orm.xml中包含以下内容:

<persistence-unit-metadata>
    <persistence-unit-defaults>
        <delimited-identifiers/>
    </persistence-unit-defaults>
</persistence-unit-metadata>

但是我已经注释了我的类,并且没有orm.xml,只有一个persistence.xml,根据同一来源,我不能包含该属性。还有其他地方我可以指定:

eclipselink.database.delimiters = true

当通过 @PersistenceContext 注入实际的实体管理器时吗?

谢谢!

更新:

谢谢詹姆斯。我最终得到了以下 orm.xml 并且它完美地完成了任务!

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="1.0" xmlns="http://java.sun.com/xml/ns/persistence/orm"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                           xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd">
<persistence-unit-metadata>
    <persistence-unit-defaults>
        <delimited-identifiers/>
    </persistence-unit-defaults>
</persistence-unit-metadata>
</entity-mappings>

I have a two entity classes called User and Group, both reserved words that need to be delimited in order for the database to accept them as tables. Annotating the entities with:

@Table(name = "\"USER\"")

does the trick, but I read that EclipseLink allows you to specify a global that automatically delimits names. According to http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg03434.html, you need to include the following in orm.xml:

<persistence-unit-metadata>
    <persistence-unit-defaults>
        <delimited-identifiers/>
    </persistence-unit-defaults>
</persistence-unit-metadata>

I have annotated my classes however, and do not have an orm.xml, only a persistence.xml, where, according to the same source, I cannot include that property. Is there anywhere else I can specify:

eclipselink.database.delimiters = true

when the actual entity manager is being injected through @PersistenceContext?

Thanks!

Update:

Thanks James. I ended up with the following orm.xml and it does the trick perfectly!

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="1.0" xmlns="http://java.sun.com/xml/ns/persistence/orm"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                           xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd">
<persistence-unit-metadata>
    <persistence-unit-defaults>
        <delimited-identifiers/>
    </persistence-unit-defaults>
</persistence-unit-metadata>
</entity-mappings>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墟烟 2024-12-02 12:40:24

您应该能够添加一个 orm.xml,它只需要有这个设置,您仍然可以在注释中定义所有映射。

You should be able to add an orm.xml, it only needs to have this setting, you can still define all of your mappings in annotations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文