2 Replies Latest reply on Jun 1, 2009 4:36 AM by taranis

    JBoss 4.2.2.GA Hibernate configuration through JTA throws no

    madhuranjans

      I am trying to configure JTA based Transaction for Hibernate on JBoss-4.2.2.GA. When I call persist nothing happens. When i put a flush after persist it throws javax.persistence.TransactionRequiredException: no transaction is in progress.

      Below are the configurations and others:
      persistence.xml

      <persistence 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"
      version="1.0">
      <persistence-unit name="Manager1" transaction-type="JTA">
      org.hibernate.ejb.HibernatePersistence
      <jta-data-source>java:/CRUISELIVE_DS</jta-data-source>
      <!--<mapping-file>ormap.xml</mapping-file>-->
      <jar-file>hibernate-ejb3-orm.jar</jar-file>
      com.thunder.gds.core.orm.hibernate.Account


      <!---->






      </persistence-unit>


      Content of Account.java class

      @Entity
      @Table(name="Account"
      ,schema="dbo"
      ,catalog="cruiselive"
      )
      public class Account implements java.io.Serializable {


      private int ID;
      private BigDecimal amt;
      private String name;

      public Account() {
      }


      public Account(int ID) {
      this.ID = ID;
      }
      public Account(int ID, BigDecimal amt, String name) {
      this.ID = ID;
      this.amt = amt;
      this.name = name;
      }

      @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
      @Column(name="ID", unique=true, nullable=false)
      public int getID() {
      return this.ID;
      }

      public void setID(int ID) {
      this.ID = ID;
      }

      @Column(name="amt", precision=12, scale=4)
      public BigDecimal getAmt() {
      return this.amt;
      }

      public void setAmt(BigDecimal amt) {
      this.amt = amt;
      }

      @Column(name="name")
      public String getName() {
      return this.name;
      }

      public void setName(String name) {
      this.name = name;
      }


      Code Where I am trying to execute and I am getting error:

      EntityManagerFactory emf = Persistence.createEntityManagerFactory("Manager1");
      EntityManager em = emf.createEntityManager();
      ac = new Account();
      ac.setName("Madhu" + new Date());
      ac.setAmt(new BigDecimal("50.45"));
      em = emf.createEntityManager();
      em.persist(ac);
      em.flush();
      em.close();

      I tried all possible things but did not able to start the transaction. What step i am missing. Please help me resolve. My database is SQL Server 2005.

        • 1. Re: JBoss 4.2.2.GA Hibernate configuration through JTA throw
          madhuranjans

          It seems that part of persistence.xml is not visiable. Here it is:

          >persistence-unit name="Manager1" transaction-type="JTA"<
          >provider<org.hibernate.ejb.HibernatePersistence>/provider<
          >jta-data-source<java:/CRUISELIVE_DS>/jta-data-source<
          >jar-file<hibernate-ejb3-orm.jar>/jar-file<
          >class<com.thunder.gds.core.orm.hibernate.Account>/class<
          >properties<
          >property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/<
          >property name="jboss.entity.manager.jndi.name" value="java:/Manager1"/<
          >property name="jboss.entity.manager.factory.jndi.name" value="java:/Manager1Factory"/<
          >property name="hibernate.show_sql" value="true"/<
          >property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/<
          >property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/<
          >/properties<
          >/persistence-unit<

          • 2. Re: JBoss 4.2.2.GA Hibernate configuration through JTA throw
            taranis

            I have the same problem, no data is written to DB although there's no exception. I had even debugged Hibernate source code, it turns out Hibernate thinks my class is Transient even i annaotated it with @Entity. I think this is the problem but haven't find a solution yet, have you?