有没有一种方法来初始化EntityManager
没有定义的持久性单元?您能否提供创建实体管理器所需的所有属性?我需要EntityManager
在运行时从用户的指定值创建.不能更新persistence.xml
和重新编译.
关于如何做到这一点的任何想法都受到欢迎!
在persistence.xml JPA配置文件中,您可以使用如下行:
<persistence-unit name="com.nz_war_1.0-SNAPSHOTPU" transaction-type="JTA">
Run Code Online (Sandbox Code Playgroud)
或有时:
<persistence-unit name="com.nz_war_1.0-SNAPSHOTPU" transaction-type=”RESOURCE_LOCAL”>
Run Code Online (Sandbox Code Playgroud)
我的问题是:
transaction-type="JTA"
和之间有什么区别transaction-type=”RESOURCE_LOCAL”
?
我还注意到一些缺少事务类型的persistence.xml文件.这是对的吗?
在网上快速搜索显示3或4个变体人们如何指定xmlns
和xsi:schemaLocation
进入persistence.xml
.
指定JPA 2.1版的"正确"方式是什么?
我正在使用:
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
Run Code Online (Sandbox Code Playgroud) 当我们使用Hibernate配置数据源时,我们应该添加hibernate.dialect
属性(或者eclipselink.target-database
如果您使用的是EclipseLink).
我想知道方言的含义是什么?我根据Hibernate的文档配置了这个属性,但我不知道它的含义是什么.
在工作中,我们有一个实体库,由几个客户端用于库(几个servlet,一个桌面应用程序等).实体库由JPA-Annotated类组成,最突出的是persistence.xml.
所有项目都使用maven配置.
应该在哪里放置persistence.xml文件?它需要位于该实体库的jar文件中,我不知道如何使用maven配置它.
(我们只是将一个项目分成几个较小的项目)
'''UPDATE'''要清楚这一点,有一个Maven-Project A包含persistence.xml,另一个(B)依赖于该Project.我把persistence.xml放在A中的src/main/resources/META-INF/persistence.xml中,当试图在A里面使用一个EntityManager时,没问题,insidie B:没什么用.
EclipseLink提供以下警告:
[EL Warning]: The collection of metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element
Run Code Online (Sandbox Code Playgroud)
我怀疑找不到persistence.xml,但它存在于目标jar中.
我现在正在使用JPA 2.0项目(在Eclipse Indigo中).在我的persistence.xml文件中,我需要指定两个<persistence-unit>标记,因为我有两个不同的数据库可以使用.这样做,我得到以下警告:
定义了多个持久性单元 - 仅识别第一个持久性单元
更重要的是,如果我创建我的实体并将其放在我的第二个<persistence-unit>中,我会收到一个错误,说我的实体未在持久性单元中声明:
类"my.package.MyClass"已映射,但未包含在任何持久性单元中
所以,问题是:是否可以在persistence.xml文件中声明(并按预期使用它们)许多<persistence-unit>标记?如果是,我需要做些什么才能获得准确的行为?
谢谢!
有没有人知道一个链接,帖子,书或其他什么解释和名义化你需要并可以在persistence.xml文件中使用的所有属性?
我有一个使用SchemaUpdate的主方法在控制台上显示要更改/创建的表,它在我的Hibernate项目中工作正常:
public static void main(String[] args) throws IOException {
//first we prepare the configuration
Properties hibProps = new Properties();
hibProps.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("jbbconfigs.properties"));
Configuration cfg = new AnnotationConfiguration();
cfg.configure("/hibernate.cfg.xml").addProperties(hibProps);
//We create the SchemaUpdate thanks to the configs
SchemaUpdate schemaUpdate = new SchemaUpdate(cfg);
//The update is executed in script mode only
schemaUpdate.execute(true, false);
...
Run Code Online (Sandbox Code Playgroud)
我想在JPA项目中重用此代码,没有hibernate.cfg.xml文件(也没有.properties文件),而是一个persistence.xml文件(在JPA规范中指定的META-INF目录中自动检测) .
我尝试过这么简单的改编,
Configuration cfg = new AnnotationConfiguration();
cfg.configure();
Run Code Online (Sandbox Code Playgroud)
但是那个例外失败了.
Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
Run Code Online (Sandbox Code Playgroud)
有人这样做过吗?谢谢.
在Eclipse中出现"在项目中找不到persistence.xml文件"错误.
目标:创建一个新项目GWT + App引擎+ Maven
创建此步骤的步骤:
然后我得到上面的错误.
该文件存在于scr/META-INF/persistence.xml以及war/WEB-INF/classes/META-INF/persistence.xml但未找到.
注意:我安装了插件m2e,m2e-wtp和google eclipse插件
persistence.xml中的持久性单元是在构建应用程序期间创建的.由于我想在运行时更改数据库URL,有没有办法在运行时修改持久性单元?我应该在分发之后使用除预绑定之外的不同数据库.
我正在使用EclipseLink(JPA 2.1)