gpt4 book ai didi

hibernate - JPA : Could not locate TransactionManager

转载 作者:行者123 更新时间:2023-12-03 17:58:03 28 4
gpt4 key购买 nike

我在 JSF 2 项目中使用 JPA 2,所以我在 GlassFish v3 中配置了我的数据源,一切都很好,但是如果我尝试在 Hibernate Tools 中测试 JPA 查询,它会给我以下错误:

Sessionfactory error:Could not locate TransactionManager

这是我的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="SuaParte" transaction-type="JTA">
<jta-data-source>jdbc/suaparte_ds</jta-data-source>
<class>entity.Area</class>
<properties>
<property name="eclipselink.logging.level" value="FINE"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
</properties>


</persistence-unit>
</persistence>

我在 Eclipse JSF 2 项目中使用 EclipseLink 2.3 (Indigo) 和 JPA 2。

编辑
遵循@fonini 方法,我的 hibernate.properties:
hibernate.connection.username=<filled>
hibernate.connection.password=<filled>
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.url=<filled>
hibernate.connection.provider_class=org.hibernate.connection.DriverManagerConnectionProvider
hibernate.datasource=jdbc/suaparte_ds
hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JBossTransactionManagerLookup

但现在给了我另一个错误:
error

我是否必须更改 id generator在我的实体中?
    @Entity
@Table(name="product")
public class Product implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE)
private Integer id;

@Size(max=150, message="150 caracteres no máximo")
private String description;

// getters and setter
}

最佳答案

由于 Hibernate Tools 在 Eclipse 中运行,因此它无法访问特定于应用程序服务器的数据源。

您可以使用属性文件来设置将覆盖数据源的连接。

这是一个示例文件:

hibernate.connection.username=user
hibernate.connection.password=pass
hibernate.connection.driver_class=org.PostgreSQL.Driver
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.connection.url=jdbc:postgresql...

hibernate.connection.provider_class=org.hibernate.connection.DriverManagerConnectionProvider
hibernate.datasource=
hibernate.transaction.manager_lookup_class=

关于hibernate - JPA : Could not locate TransactionManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8049663/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com