我在一个JSF 2项目中使用JPA 2,因此我在GlassFish v3中配置了我的数据源,一切都很好,但是如果我尝试在Hibernate工具中测试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](https://istack.dev59.com/bNtDr.webp)
@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
}