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.