JPA数据库分隔符 [英] JPA database delimiters

查看:106
本文介绍了JPA数据库分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为User和Group的两个实体类,两个保留字都需要分隔,以便数据库将它们作为表接受。用以下内容注释实体:

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\"")

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

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>

但是我注释了我的类,并且没有orm.xml,只有persistence.xml ,根据相同的来源,我不能包括该财产。还有其他我可以指定的地方:

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

当通过@PersistenceContext注入实际实体经理时?

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

谢谢!

更新:

谢谢詹姆斯。我最终得到了以下 orm.xml ,它完美地完成了这一操作!

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>


推荐答案

你应该能够添加一个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.

这篇关于JPA数据库分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆