transactions and distributed transactions in ejb3
grdzeli_kaci Jul 7, 2006 11:02 AMfierst of all sorry for my english :)
1.I've jboss-4.0.4.GA configured with EJB3 and it was working fine before i deside working with transaction. :)
i have one entity bean (for example Student) and one stateless session bean like this :
TransactionManagement(value = TransactionManagementType.BEAN) @Remote(StudentFasade.class) public @Stateless class StudentFasadeBean implements StudentFasade { @PersistenceContext private EntityManager manager; @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public Long addStudent(Student stbean) throws MagtiException { try { manager.getTransaction().begin(); manager.persist(_student); manager.getTransaction().commit(); return _student.getId(); } catch (Exception e) { manager.getTransaction().rollback(); } } }
and this is my persistance.xml file :
<?xml version="1.0" encoding="UTF-8" ?> <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="Students Registration" transaction-type="JTA"> <jta-data-source>java:/XAOracleDS</jta-data-source> <class>com.magti.businesslayer.ejb3entity.Student</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/> <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/> <property name="hibernate.connection.url" value="jdbc:oracle:thin:@192.9.200.177:1521:devnbtwo"/> <property name="hibernate.connection.username" value="paata"/> <property name="hibernate.connection.password" value="1982226"/> <property name="hibernate.default_schema" value="PAATA"/> </properties> </persistence-unit> </persistence>
and in client side i get error like this:
Exception in thread "main" java.lang.IllegalStateException: Illegal to call this method from injected, managed EntityManager at org.jboss.ejb3.entity.TransactionScopedEntityManager.getTransaction(TransactionScopedEntityManager.java:219)
and one other question :) how i can workig with distributed transactions in ejb3 (i mean that bean insert two different database and i want manage both transaction of them)
thanks .....