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.  [ 4 posts ] 
Author Message
 Post subject: Problems with Hibernate as JPA provider in weblogic10
PostPosted: Wed Jul 30, 2008 6:34 am 
Newbie

Joined: Thu Mar 27, 2008 11:45 am
Posts: 10
Location: Russia
Hellow
I'm trying to use hibernate as JPA provider for EJB30 under weblogic10 and I have problems with transactions.
So my test application is:
- One Entity Bean wich maps table in Data Base
- One Session(Stateless) EJB with two methods. In first method I Create new record in Db table using Entity bean
And in second method I check this adding of new record.

Entity Bean:
Code:
package test.entity;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.Column;

@Entity
@Table(name = "TEST_ENTITY")
public class EntityTest {

    @Id
    @Column(name = "ID")
    private Integer id;

    @Column(name = "NAME")
    private String name;


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

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

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        final EntityTest review = (EntityTest) o;

        return id.equals(review.id);
    }

    public int hashCode() {
        return id;
    }

}


Session Bean:
Code:
package test.second;

import test.entity.EntityTest;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.PersistenceContext;
import javax.persistence.EntityManager;
import java.util.List;

@Stateless(name = "SessFacadEJB", mappedName = "second")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class SessFacadBean implements SessFacad{

    @PersistenceContext(unitName = "pointBaseDemoUnit_For_Second")
    EntityManager em;

    public SessFacadBean() {
    }

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void testEntity() {
        List result = em.createQuery("select x from EntityTest x").getResultList();
        int i = 1;
        for (Object o : result) {
            EntityTest et = (EntityTest) o;
            System.out.println("id[" + et.getId() + "] name[" + et.getName() + "]");
            i++;
        }

        EntityTest newEt = new EntityTest();
        newEt.setId(i);
        newEt.setName("Test_Name_" + i);
        em.persist(newEt);

        System.out.println("Entity with id: " + i + "added");
    }

    public int checkAdding() {
        Integer result = (Integer) em.createQuery("select max (x.id ) from EntityTest x").getSingleResult();
        System.out.println("Max id: " + result);
        return result;
    }
}


And persistence.xml:
Code:
<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="pointBaseDemoUnit_For_Second" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>demo.pointbase.datasource</jta-data-source>
        <class>test.entity.EntityTest</class>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PointbaseDialect"/>
            <property name="show_sql" value="true"/>
            <property name="hibernate.transaction.manager_lookup_class"    value="org.hibernate.transaction.WeblogicTransactionManagerLookup"/>
            <property name="hibernate.transaction.factory_class"           value="org.hibernate.transaction.CMTTransactionFactory"/>
            <property name="hibernate.query.factory_class" value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>
        </properties>
    </persistence-unit>
</persistence>


So when I call first method(testEntity()) and then call second(checkAdding()), - nothing happends. I mean that nothig is added to Data Base.

When I change persistence.xml file to:
Code:
<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="pointBaseDemoUnit_For_Seconf" transaction-type="JTA">
        <jta-data-source>demo.pointbase.datasource</jta-data-source>
    </persistence-unit>
</persistence>

In this case default JPA provider for weblogic works(Open JPA provider) and all works correctly.

So I just want hibernate provider to work correctly.

Thanks for looking.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 01, 2008 4:51 am 
Newbie

Joined: Thu Mar 27, 2008 11:45 am
Posts: 10
Location: Russia
Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 01, 2008 6:54 am 
Newbie

Joined: Thu Mar 27, 2008 11:45 am
Posts: 10
Location: Russia
Well, problem fixed. I checked hibernate logs and found out such message wich occured while invoking ejb's method:
Code:
2008.08.01-13:17:05,947 DEBUG SessionImpl : opened session at timestamp: 12175822259
2008.08.01-13:17:05,947 DEBUG JDBCContext : successfully registered Synchronization
2008.08.01-13:17:05,947 DEBUG AbstractEntityManagerImpl : Looking for a JTA transaction to join
2008.08.01-13:17:05,947 WARN  AbstractEntityManagerImpl : Cannot join transaction: do not override hibernate.transaction.factory_class


so, after I removed from persistence.xml property hibernate.transaction.factory_class all begin to work.


Top
 Profile  
 
 Post subject: Re: Problems with Hibernate as JPA provider in weblogic10
PostPosted: Sat May 16, 2009 3:07 pm 
Newbie

Joined: Sat May 16, 2009 3:02 pm
Posts: 1
This way is not to use Hibernate linking.
but i have same problem and no idea yet,
about use Hibernate 3 and weblogic 10.3 Transaction problem


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.