-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Sessionfactory error with JPA in Hibernate Tools
PostPosted: Wed May 06, 2009 4:17 pm 
Newbie

Joined: Mon Jun 20, 2005 2:51 pm
Posts: 13
Location: Brasil
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;
   }   
   
   
}

_________________
Skype: 'axelberle'


Top
 Profile  
 
 Post subject: Re: Sessionfactory error with JPA in Hibernate Tools
PostPosted: Wed May 06, 2009 7:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
The problem is that when you create a sessionfactory in eclipse you are using "j2se" JPA meaning no access to a TX Manager nor to a jta-data-source.

Luckily, you can overwrite this via a property file and if you create a seam project you will see a hibernate-console.properties file be created which have the appropriate defaults for j2se.

We should actually warn against this and possibly even force it through, but we don't in the current release.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.