Hi!
I am trying to use Hibernate Tools in JBoss Developer Studio 2.0 in a simple JPA project (with one single entity) but I always get the following error message when trying to open or rebuild
the session factory:
<Sessionfactory error: The chosen transaction strategy requires access to the JTA TransactionManager>.
This is confusing because I specified a persistence context with a jta-data-source and the deployed project works fine, I just cannot get it to work with Hibernate Tools.
(With a non-JPA project I got the Hibernate Tools to work though.)
I am using JBossAS 5, JBoss Developer Studio 2.0,
Hibernate Tools version 3.2.4.GA-R200903141626-h5
Any help would be greatly appreciated!
Axel
Here are my files:
Code:
<?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="IndiabelaPersistence" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/PostgresDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
</properties>
</persistence-unit>
</persistence>
My Data-Source "PostgresDS" is defined in "postgres-ds.xml":
Code:
<datasources>
<local-tx-datasource>
<jndi-name>PostgresDS</jndi-name>
<connection-url>jdbc:postgresql://localhost:5432/mydb</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<user-name>xxx</user-name>
<password>yyy</password>
<min-pool-size>9</min-pool-size>
<max-pool-size>99</max-pool-size>
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>PostgreSQL 8.1</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
My only entity is the following:
Code:
package indiabela.business.model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
@Table(name = "cadastro")
public class Cadastro {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "id")
private Long id;
@Column(name="nome", length=100, nullable=false)
private String nome;
@Column(name="sobrenome", length=100, nullable=false)
private String sobrenome;
@Column(name="email", length=100, nullable=false)
private String email;
@Column(name="telefone", length=100, nullable=true)
private String telefone;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "data_criacao", nullable=false)
private Date dataCriacao;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "data_modificacao", nullable=true)
private Date dataModificacao;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getSobrenome() {
return sobrenome;
}
public void setSobrenome(String sobrenome) {
this.sobrenome = sobrenome;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getTelefone() {
return telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
public Date getDataCriacao() {
return dataCriacao;
}
public void setDataCriacao(Date dataCriacao) {
this.dataCriacao = dataCriacao;
}
public Date getDataModificacao() {
return dataModificacao;
}
public void setDataModificacao(Date dataModificacao) {
this.dataModificacao = dataModificacao;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((email == null) ? 0 : email.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Cadastro other = (Cadastro) obj;
if (email == null) {
if (other.email != null)
return false;
} else if (!email.equals(other.email))
return false;
return true;
}
}