我有一个maven启用的项目导入到Eclipse中.从Eclipse,我得到一个错误"没有生成器命名"system-uuid"在以下行的system-uuid部分的持久性单元中定义":
@Id @GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Column(length = 36)
public String getId() {
return id;
}
Run Code Online (Sandbox Code Playgroud)
项目从命令行正确构建.是什么导致Eclipse生成此错误,我该如何解决?
持久性文件看起来像这样..
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="xxxx"/>
</persistence>
Run Code Online (Sandbox Code Playgroud) 当我的persistence.xml文件的位置时,我感到难过.我正在使用eclipselink 2.4作为我的JPA 2.0实现,并且我的persistence.xml位于src/main/resources/META-INF/persistence.xml下,因为许多帖子状态.
第一个问题:在eclipse中发布到我的服务器后,我收到一条错误,指出我找不到我的persistence.xml.
Exception: : java.lang.IllegalArgumentException: No persistence unit named 'X'
is available in scope Webapp. Available persistence units: [] at
Run Code Online (Sandbox Code Playgroud)
这是我的persistence.xml的代码
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="X" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>localJTA</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.target-server" value="WebLogic"/>
<property name="eclipselink.logging.level" value="FINEST"/>
</properties>
</persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)
如果我将META-INF移动到webapp/WEB-INF/classes/META-INF,那么它可以工作!我无法理解问题所在.
我检查了项目构建路径,一切看起来都不错.
我遇到的第二个问题是我的带注释的实体类没有被eclipselink自动拾取.在我的JPA配置中,我有自动选择的发现注释类.
我的xml中也有以下内容
<exclude-unlisted-classes>false</exclude-unlisted-classes>
Run Code Online (Sandbox Code Playgroud)
使用的技术:weblogic 12c服务器,EJB 3.1,JPA 2.0,M2E-WTP和JSF 2.1
更新1:在路径src/main/resources/META-INF/persistence.xml上保留META-INF并执行maven install以构建war文件,META-INF文件夹正确放置在WEB-INF/classes/META-中像INF/persistence.xml一样(在战争中).似乎只是在Eclipse中构建和运行webapp的时间和问题.有谁能解释一下?
更新2:在src/main/resources中保留META-INF,即src/main/resources/META-INF/persistence.xml以及我的persistence.xml中的以下内容,而不是显式列出实体类
<exclude-unlisted-classes>false</exclude-unlisted-classes>
Run Code Online (Sandbox Code Playgroud)
如果我构建战争并通过weblogic控制台通过Internet Explorer部署它.为什么它不在日食里面工作!?
更新3:
你是否检查了构建的内容 -Yes,在Eclipse中我自动构建了set.查看项目文件夹,我看到java包com,包含persistence.xml的META-INF文件夹,以及在Webapp/target/classes下的resources文件夹.
如果战争是相同的 - 你是指你在C:\ workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\Weblogic12cDomain_auto_generated_ear_\Webapp.war中找到的Webapp.war文件夹?如果是这样,那里唯一的东西是WEB-INF\lib\jsf-impl-2.1.7.jar
然后你检查了用于在Eclipse中测试你的应用程序的类路径 - 这个条目可以在我的类路径中找到,如预期的在Webapp /下的.classpath …
persistence.xml中的持久性单元是在构建应用程序期间创建的.由于我想在运行时更改数据库URL,有没有办法在运行时修改持久性单元?我应该在分发之后使用除预绑定之外的不同数据库.
我正在使用EclipseLink(JPA 2.1)
我想利用JPA @Entity注释不要将类实体声明为J2SE persistence.xml文件.我想避免的:
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.mycompany.entities.Class1</class>
<class>com.mycompany.entities.Class2</class>
<class>com.mycompany.entities.Class3</class>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)
这是我的实际persistence.xml看起来很像
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<!-- Scan for annotated classes and Hibernate mapping XML files -->
<property name="hibernate.archive.autodetection" value="class, hbm" />
<property name="hibernate.cache.use_second_level_cache" value="false" />
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)
是否有一种标准方法可以在JAR模块中扫描persistence.xml文件中的JPA实体?是否有一种不标准的Hibernate方法从JAR模块中扫描persistence.xml文件中的JPA实体?
我正在使用JPA开发JavaSE应用程序.不幸的是,我null
打电话后:
Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
您将在下面找到:
EntityManagerFactory
并意外返回null
persistence.xml
档案我的代码片段:
public class Main {
private static final String PERSISTENCE_UNIT_NAME = "MeineJpaPU";
private static EntityManagerFactory factory;
public static void main(String[] args) {
// I get null on this line!!!
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
// do stuff with entity manager
...
}
}
Run Code Online (Sandbox Code Playgroud)
我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="MeineJpaPU" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>path.to.package.server.Todo</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.url" …
Run Code Online (Sandbox Code Playgroud) 我对glassfish,JPA等都很陌生,我在设置它时遇到了很多问题.我打算做的是一个带有持久后端的简单RESTful服务.我使用glassfish3作为应用程序服务器,并已使用jersey-library部署了一个简单的REST服务.现在我想通过JPA提供对数据库的访问.Glassfish附带JavaDB/derby和EclipseLink,是吗?所以,我想用那个:-)
我在META-INF中创建了一个persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="myPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDataSource" /> <!-- org.apache.derby.jdbc.EmbeddedDriver -->
<property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/sample;create=true" />
<property name="javax.persistence.jdbc.user" value="APP" />
<property name="javax.persistence.jdbc.password" value="APP" />
<property name="eclipselink.ddl-generation" value="create-tables" />
</properties>
</persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)
然后我在我的资源中创建了一个字段,我想访问/存储som数据:
@PersistenceUnit(unitName = "myPU")
EntityManagerFactory emf;
Run Code Online (Sandbox Code Playgroud)
但"emf"总是NULL :-(
我想我的persistence.xml配置不合适.
如果有人有提示,我做错了,真的很高兴......
谢谢!
简单的问题...
我在Eclipse环境
MainApp(企业应用程序项目)中有一些项目"包含"
问题是把persistance.xml文件放在哪里?
获取异常:java.lang.IllegalStateException:无法为unitName DataModel检索EntityManagerFactory
我正在使用tomcat连接池,jpa,hibernate.我在tomcat的context.xml中创建的数据源工作正常,如果我尝试使用它:
source = (DataSource) ((Context) c.lookup("java:comp/env")).lookup("jdbc/kids");
Run Code Online (Sandbox Code Playgroud)
但是如果我在persistence.xml中指定这个jndi数据源
<persistence-unit name="kids-tomcat" transaction-type="JTA">
<jta-data-source>jdbc/kids</jta-data-source>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)
我得到以下异常:org.hibernate.service.jndi.JndiException:无法查找JNDI名称[jdbc/kids]
不知道为什么会发生!
我想在我的应用程序的conf文件夹中有我的persistence.xml.我如何告诉Persistence.createEntityManagerFactory它应该从那里读取它?
我正在尝试将同一个实体持久化到MySQL和Postgres数据库(这主要是为了识别任何不一致,并找出执行双写的任何问题的细节 - 我在这里遇到过).我发现的文章都描述了依赖于其他框架的解决方案.我正在尝试使用Glassfish 4.0开箱即用,JPA 2.1以及EclipseLink 2.5作为JPA提供程序来解决这个问题.我正在使用Eclipse,并意识到IDE不支持在persistence.xml文件中配置多个持久性单元,所以我正在为此直接编写XML.
我期待在代码中执行类似的操作(使用相同的方法):
@PersistenceContext(name = "MyAppMySQLPU")
EntityManager emMySQL;
@PersistenceContext(name = "MyAppPostgresPU")
EntityManager emPostgres;
//...etc...
MyThing thing = new MyThing();
//...etc...
emMySQL.persist(thing);
emPostgres.persist(thing);
Run Code Online (Sandbox Code Playgroud)
并使用persistence.xml
包含以下内容的文件:
<persistence-unit name="MyAppPostgresPU">
<jta-data-source>jdbc/PostgresPool_test</jta-data-source>
<class>model.MyThing</class>
</persistence-unit>
<persistence-unit name="MyAppMySQLPU">
<jta-data-source>jdbc/MySQLPool_test</jta-data-source>
<class>model.MyThing</class>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我收到以下错误:
SEVERE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
SEVERE: Exception while preparing the app
SEVERE: Exception while preparing the app : Could not resolve a persistence unit corresponding to the persistence-context-ref-name [MyAppPostgresPU] in the scope of the module called [MyApp]. …
Run Code Online (Sandbox Code Playgroud)