- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我已经创建了非常简单的应用程序,它具有持久性上下文( hibernate 作为提供者)以从数据库中读取一些值。我将 Eclipse 与 Maven 结合使用。
首先,我得到
Caused by: org.apache.openejb.OpenEJBException: java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence cannot be cast to javax.persistence.spi.PersistenceProvider:
然后根据这个话题 http://openejb.979440.n4.nabble.com/problem-with-hibernate-persistence-provider-td980429.html我排除了 hibernate-jpa-2.0-api。现在,我的依赖项看起来
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.3.Final</version>
<exclusions>
<exclusion>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
</exclusion>
</exclusions>
</dependency>
现在,我不知道为什么...
Caused by: java.lang.ClassNotFoundException: org.hibernate.transaction.TransactionManagerLookup
但是 TransactionManagerLookup 在 hibernate-core 中。拜托,谁能告诉我,应该如何查看 pom.xml 才能在 TomEE 中使用 hibernate ?
最佳答案
<tomee-home>/lib
根据文档(http://tomee.apache.org/tomee-and-hibernate.html),以下内容就足够了,事实上它们对我有用:
<tomee-home>/lib/antlr-2.7.7.jar
<tomee-home>/lib/dom4j-1.6.1.jar
<tomee-home>/lib/hibernate-commons-annotations-4.0.2.Final.jar
<tomee-home>/lib/hibernate-core-4.2.21.Final.jar
<tomee-home>/lib/hibernate-entitymanager-4.2.21.Final.jar
<tomee-home>/lib/hibernate-validator-4.3.2.Final.jar
<tomee-home>/lib/javassist-3.18.1-GA.jar
<tomee-home>/lib/jboss-logging-3.1.0.GA.jar
所有这些 .jars
包含在 Hibernate ORM 4.2.x 下载 ( http://hibernate.org/orm/ ) 中,Hibernate Validator 除外,它是一个单独的下载 ( http://hibernate.org/validator/ )。
使用 javaee-api
范围为 provided
的 Maven 工件您现在可以在您的项目中使用 JPA 规范。但是,如果您以前一直在使用一些 Hibernate 特定的功能、类或注释,您仍然可以在 pom.xml
中引用 Hibernate。匹配这些依赖项:
<!-- JPA spec (required) -->
<dependencies>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0-4</version>
<scope>provided</scope>
</dependency>
<!-- Hibernate specific features (only if needed) -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.21.Final</version>
<scope>provided</scope>
</dependency>
编辑 <tomee-home>/conf/tomee.xml
:
<Resource id="myJtaDatabase" type="DataSource">
JdbcDriver com.mysql.jdbc.Driver
JdbcUrl jdbc:mysql://localhost:3306/my_dbname?autoReconnect=true
UserName foo
Password bar
validationQuery = SELECT 1
JtaManaged true
</Resource>
也可以把上面的<Resource>...</Resource>
定义为 WEB-INF/resources.xml
并将其与您的应用程序一起发送:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<!-- Put <Resource> elements here -->
<resources>
既然您已告诉 TomEE 如何建立连接,请在 /src/main/java/META-INF/persistence.xml
中定义一个 JTA 数据源。 :
<?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="my_persistence_unit">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:openejb/Resource/myJtaDatabase</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<!-- As many hibernate properties as you need, some examples: -->
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="true" />
<!-- Drop and then re-create the database schema (don't do this in production) -->
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
获得 EntityManager
在像这样的 CDI bean 或 EJB 中:
@PersistenceContext(unitName = "my_persistence_unit")
private EntityManager em;
我正在使用 Hibernate 4.2.21(JPA 2.0、Java EE 6)和 TomEE 1.7.2。任何 TomEE 1.7.x、1.6.x 和 1.5.x 都可以使用。但是,您不能使用 Hibernate 4.3+ (JPA 2.1/Java EE 7),因为 TomEE 1.7.x 及以下版本仅支持 Java EE 6。如果您真的想将 Java EE 7 功能与 TomEE 一起使用,这篇博文可能会有所帮助: http://rmannibucau.wordpress.com/2013/07/19/little-tip-to-help-you-to-test-javaee-7-in-tomee-with-tomee-maven-plugin/
TomEE 1.5.x 已经包含一个 javassist-<version>.jar
,所以您不必复制一个。
关于java - 如何在 Hibernate 中使用 TomEE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10852035/
我想在 TomEE 中测试 hikaricp。我已将 jar 文件添加到我的 lib 文件夹中,并尝试像这样定义资源: .... 当我这样做时,我在启动时收到以下错误: org.apache.xb
平台:TomEE Web 配置文件 1.5.0。 我正在尝试做一件非常基本的事情,为 MySQL 设置数据源。我已经阅读了官方指南(http://openejb.apache.org/configur
我最近在“Red Hat Enterprise Linux Server (6.6)”上安装了“apache-tomee-webprofile-1.7.2”。 我可以通过访问 x.x.x.x:8080
如何在 IntelliJ IDEA VM 选项中进行设置。 我需要设置 set JAVA_OPTS="-Dtomee.serialization.class.whitelist=" set CATAL
正如标题所说。我对 Java EE6 认证的内部工作原理了解不多。但是,TomEE+ 似乎只是 TomEE 的超集,所以 TomEE+ 不应该也通过 Java EE6 认证吗? 我们刚刚决定为我们内部
我正在使用 Apache TomEE(本地主机上的 apache-tomee-plus-1.5.2)处理一些 JEE 网络应用程序,并尝试从 TomEE 主页上的链接访问这些服务。 现在,我记得早些时
尝试在 Windows 上启动 TomEE 时出现以下错误: SEVERE: OpenEJBContextConfig.processAnnotationsFile: failed. java.uti
我的服务器有 48 个 CPU,在 TomEE+ 7.0.2 上托管 Java EE 7 REST API。 一些 API 在运行并行算法时需要使用尽可能多的 CPU。 并行化部分不需要任何数据库或其
所以我试图找到任何引用文档或使用这三个的重要示例。 我发现的“最好的”是: TomEE/OpenEJB JAXRS refactoring Some tips for TomEE andJAXRS c
我正在 TomEE 8 中运行我的应用程序。我想从我的数据库中读取一些属性并将其传递给应用程序。 我看到了 https://rmannibucau.wordpress.com/2014/08/06/t
我正在使用单个 TomEE 实例来部署 2 个 Web 应用程序。两个应用程序使用不同的数据库和不同的实体。 应用程序 2 集成到应用程序 1 中,因此我在运行时随时需要这两个架构。 我在 tomee
假设我有一个包含 persistence.xml 配置和 jpa 实体的 jar。我希望在不同的应用程序之间共享相同的持久性单元。 例如,部署一个 war 应用程序并注入(inject)相同的持久性单
规范:jdk1.8,TOMEE702,win10 问题:为 open-ejb3.X 安装和使用 TOMEE 的方法/内容/哪个? 网址:http://tomee.apache.org/download
我下载并安装了 TomEE 1.7.1。在启动服务器时抛出 IllegalArgumentException。 可能是什么问题,因为我还没有部署任何应用程序。 INFO: Using 'openejb
我有一个关于 TomEE 和使用 tomee.xml 中指定的数据源的奇怪问题。值得注意的是,我使用的是 Netbeans、TomEE 和 MySQL。在 Ubuntu 13.04(Xubuntu 最
无法部署应用程序,但出现异常 java.lang.Exception:持久性单元:持久性 -750441533localhost:未找到名称“openejb/PersistenceUnit/persi
我已经编写了代码,以便可以在不重新启动服务器的情况下更改 EntityManagerFactory 属性。我使用 RESTful Jersey 服务对其进行了测试。 我应该编写junit测试来测试这个
我想将 war 文件部署到 TomEE 但失败了: 原因: javax.naming.NameNotFoundException: Name openejb/Resource/applic
我在 Eclipse 中工作。我已经添加了一个启动良好的 TomEE 服务器,但似乎在创建 MySQL 数据源时出现问题。 我在 TomEE 1.7.2 中定义了以下数据源: jdbcDri
我们正在尝试从 GlassFish 迁移到 TomEE,但是在 TomEE 上部署自定义资源适配器时遇到了问题。在 GlassFish 上,只需部署 RAR 文件、配置资源适配器配置,仅此而已。我们如
我是一名优秀的程序员,十分优秀!