JPA 数据库分隔符
我有两个实体类,称为“用户”和“组”,这两个保留字都需要分隔,以便数据库将它们接受为表。用: 注释实体
@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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够添加一个 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.