- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
包括我在内的一些人一直在努力将来自不同模块(jar)的实体合并到一个持久化单元中(尤其是 JavaSE,例如这里的 JPA 2.0: Adding entity classes to PersistenceUnit *from different jar* automatically)。根据答案,没有简单的直接方法可以做到这一点。一种解决方案是在单个持久性单元文件中列出所有 jar 中的所有类,但这并不是很优雅。我可能不小心找到了另一种方法。通常我所有的实体类都使用注解进行映射。至于解决方法:persistence.xml
可以包含多个 XML 映射文件,例如:
main.jar!META-INF/persistence.xml:
<persistence-unit name="PU" transaction-type="RESOURCE_LOCAL">
<mapping-file>META-INF/order-mappings.xml</mapping-file>
<mapping-file>META-INF/customer-mappings.xml</mapping-file>
</persistence-unit>
映射文件可以放在不同的 jar 中。我注意到它们可能包含 <entity>
没有任何属性的元素,例如:
order.jar!META-INF/order-mappings.xml
<entity-mappings>
<entity class="com.company.Order"></entity>
</entity-mappings>
即使映射文件没有映射任何属性Java 类中的注释仍然会被考虑,一切似乎都正常!这意味着只需包含来自特定 JAR 的 XML 映射文件,就可以轻松地将来自多个 jar 的实体包含到单个持久性单元中。
我的问题是:这是允许的 JPA 映射文件使用还是我的持久性提供程序 (Hibernate) 的副作用?
最佳答案
是的,JPA 规范允许这样做。
XML 实体映射旨在覆盖 JPA 注释。除非您使用 <xml-mapping-metadata-complete/>
专门更改默认行为标记,JPA 提供者将在没有 XML 映射的地方使用注释。
这里是 JPA 2.0 spec 的摘录:
12.1 Use of the XML Descriptor
... The absence orpresent of the xml-mapping-metadata-complete subelement contained inthe persistence-unit-defaults subelement of the entity-mappingselement controls whether the XML object/relational mapping descriptoris used to selectively override annotation values or whether it servesas a complete alternative to Java language metadata annotations.
Ifthe xml-mapping-metadata-complete subelement is specified, thecomplete set of mapping metadata for the persistence unit is containedin the XML mapping files for the persistence unit, and any persistenceannotations on the classes are ignored.
关于java - 多个 jar ,单个持久性单元解决方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15026302/
我只是想知道要安装哪个版本的 Visual Studio 2010(专业版或高级版)提示升级项目.. 项目包括:asp.net mvc、数据库和silverlight。 最佳答案 通常,由不同版本的相
目录 前言 四、技术选型 五、后端接口设计 5.1业务系统接口 5.2App 端接口 六、关键逻辑实现 6.1Red
目录 前言 一、需求分析 1.1发送通知 1.2撤回通知 1.3通知消息数 1.4通知消息列表 二、数据模型设计
目录 前言 一、多租户的概念 二、隔离模式 2.1独立数据库模式 2.2共享数据库独立数据架构 2.3共享数据库共享数据架构
导读: 虽然锁在一定程度上能够解决并发问题,但稍有不慎,就可能造成死锁。本文介绍死锁的产生及处理。 死锁的产生和预防 发生死锁的必要条件有4个,分别为互斥条件、不可剥夺条件、请求与保持条件和循环等待条
在浏览网页后,我找不到任何功能来执行此操作,我有可行的个人解决方案。也许它对某人有用。 **使用 Moment 插件转换日期。***moment(currentPersianDate).clone()
是否有一种解决方案可以很好地处理数字(1-10)手写?我试过tesseract,但我得到的只是垃圾。 理想情况下是 OSS,但商业也可以。 最佳答案 OpenCV 现在带有手写数字识别 OCR 示例。
在服务器应用程序上,我们有以下内容:一个称为 JobManager 的单例类。另一个类,Scheduler,不断检查是否需要向 JobManager 添加任何类型的作业。 当需要这样做时,调度程序会执
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 5年前关闭。 Improve this qu
当您尝试从 GitHub 存储库安装某些 R 包时 install_github('rWBclimate', 'ropensci') 如果您遇到以下错误: Installing github repo
问题在以下链接中进行了描述和演示: Paul Stovell WPF: Blurry Text Rendering www.gamedev.net forum Microsoft Connect: W
我正在寻找一种解决方案,使用标准格式 a × 10 b 在科学记数法下格式化 R 中的数字。一些同行评审的科学期刊都要求这样做,并且手动修改图表可能会变得乏味。 下面是 R 标准“E 表示法”的示例,
已编辑解决方案(如下...) 我有一个启动画面,它被打包到它自己的 jar 中。它有效。 我可以通过以下方式从另一个 java 应用程序内部调用 Splash.jar: Desktop.getDesk
什么是创建像 PageFlakes 或 iGoogle 这样的门户网站的好框架/包? ?我们希望创建一个为员工提供 HR 服务的员工/HR 门户,但我们也需要一种足够灵活的产品,以便我们可以使用它来为
我正在寻找一种解决方案,使用标准格式 a × 10 b 在科学记数法下格式化 R 中的数字。一些同行评审的科学期刊都要求这样做,并且手动修改图表可能会变得乏味。 下面是 R 标准“E 表示法”的示例,
如何将 solr 与 heritrix 集成? 我想使用 heritrix 归档一个站点,然后使用 solr 在本地索引和搜索该文件。 谢谢 最佳答案 使用 Solr 进行索引的问题在于它是一个纯文本
完整日历不包含工作时间功能选项(在任何一天的议程 View 中选择第一行和最后一行 - 例如公司不工作)。我做到了类似的事情: viewDisplay: function(view){
我正在使用 bootstrap 作为我的下拉菜单。但有一个问题, 如果我的下拉菜单有多级子菜单,那么它会显示在屏幕上,并出现底部滚动条。 如何将子菜单保留在屏幕内,我需要一个 jQuery 解决方案。
我有一个要转换为 C# 的 Excel 宏。目前我手动转到一个已经打开的 IE 窗口,从中复制所有内容(html 表)并粘贴到 excel 工作表中。然后我正在处理数据。这非常有效,因为将 html
我用谷歌搜索了一下,但没有找到好的结果。 现在我正在构建一个网站,我试图从一开始就从设计的角度使其尽可能正确。 我现在面临的问题是,在决定开始使用日志记录时,我需要一个项目来放置这段代码。由于我无法在
我是一名优秀的程序员,十分优秀!