如何获取使用EJB 3.1,Hibernate 3.6,JPA 2.0,JBoss和MySQL的容器管理事务(CMT) [英] How to get Container Managed Transactions (CMT) working with EJB 3.1, Hibernate 3.6, JPA 2.0 , JBoss and MySQL

查看:176
本文介绍了如何获取使用EJB 3.1,Hibernate 3.6,JPA 2.0,JBoss和MySQL的容器管理事务(CMT)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让CMT与JPA EntityManagers和EJB一起工作,但是出现了以下错误。 (stack trance truncated):

 导致:java.lang.RuntimeException:**无法解析@EJB引用:[EJB参考:beanInterface'com.mydomain.beans.TestBean2',beanName'testBean2',mappedName'null',lookupName'null',**拥有单元'AbstractVFSDeploymentContext @ 2008455195 {vfs:/// Users / willtardy / Documents / workspace / .metadata / .plugins / org.jboss.ide.eclipse.as.core / JBoss_6.0_Runtime_Server1300532851414 / deploy / mydomainWeb.war}'] 
用于环境条目:env / com.mydomain.action.SearchAction / testBean in单元AbstractVFSDeploymentContext @ 2008455195 {vfs:///Users/willtardy/Documents/workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.0_Runtime_Server1300532851414/deploy/mydomainWeb.war}

我的类:



访问会话Bean的Servlet:

  public class SearchActionExample extends Action {
@EJB
private static TestBeanServiceInterface t estBean;

public ActionForward执行(ActionMapping映射,ActionForm表单,HttpServletRequest请求,HttpServletResponse响应)throws异常{
testBean.addSource(TEST SOURCE NAME,88,99);
服务服务= testBean.findService(HBA,MEL);

return mapping.findForward(success);
}
}

远程界面:

  @Remote 
public interface TestBeanServiceInterface {
//源是我自己的自定义实体
void addSource(String sourceName,int newthreadsleeptime ,int maxactivehttpclients);

//服务是我自己的自定义实体
服务findService(String departureAirportCode,String arrivalAirportCode);
}

无状态会话Bean定义:

  @Stateless 
public class TestBeanService实现TestBeanServiceInterface {

@PersistenceContext(unitName =mydomainJPA)
private EntityManager em;

public void addSource(String sourceName,int newthreadsleeptime,int maxactivehttpclients){
源source = new Source();
source.setName(sourceName);
source.setNewThreadSleepTime(newthreadsleeptime);
source.setMaxActiveHttpClients(maxactivehttpclients);
em.persist(source);
}
public Service findService(String departureAirportCode,String arrivalAirportCode){
String queryString =from Service where departureairportcode ='+ departureAirportCode +'和arrivalairportcode ='+ arrivalAirportCode +' ;
服务服务=(服务)em.createQuery(queryString).getSingleResult();
退货服务;
}
}

file persistnce.xml:

 <?xml version =1.0encoding =UTF-8?> 
< persistence xmlns =http://java.sun.com/xml/ns/persistencexmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexsi:schemaLocation =http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsdversion =2.0>
< persistence-unit name =mydomainJPAtransaction-type =JTA>
< provider> org.hibernate.ejb.HibernatePersistence< / provider>
< jta-data-source> java:/ MySqlDS< / jta-data-source>
< class> com.mydomain.entities.Service< / class>
< class> com.mydomain.entities.Source< / class>
<属性>
< property name =hibernate.query.factory_classvalue =org.hibernate.hql.classic.ClassicQueryTranslatorFactory/>
< property name =hibernate.archive.autodetectionvalue =class/>
< property name =hibernate.transaction.manager_lookup_classvalue =org.hibernate.transaction.JBossTransactionManagerLookup/>
< property name =hibernate.current_session_context_classvalue =jta/>
< / properties>
< / persistence-unit>



当它说无法解决参考,我可以在哪里定义bean? EJB3不需要ejb-jar.xml。有没有其他的配置文件,我失踪了?






更新:




  • 我已经更新了上面的代码段,以便根据下面的答案将bean创建为接口类型。 >


  • 需要在web.xml中定义或映射EJB?


  • 假设在web.xml中需要引用,我已经在web.xml中添加了一个EJB参考(见下文),但是现在我收到一个新的错误(见下文)




行添加到web.xml:

 < ejb-ref> 
< ejb-ref-name> ejb / TestBeanEJBname< / ejb-ref-name>
< ejb-ref-type>会话< / ejb-ref-type>
< home> com.mydomain.action.TestBeanService< / home>
< remote> com.mydomain.action.TestBeanServiceInterface< / remote>
< / ejb-ref>

新收到的错误消息:

  12:11:00,980错误[org.jboss.kernel.plugins.dependency.AbstractKernelController]安装到PostClassLoader时出错:name = vfs:/// Users / willtardy / Documents / workspace /。 metadata / .plugins / org.jboss.ide.eclipse.as.core / JBoss_6.0_Runtime_Server1300532851414 / deploy / purejetWeb.war state = ClassLoader mode = Manual requiredState = PostClassLoader:org.jboss.deployers.spi.DeploymentException:java.lang。 IllegalStateException:找不到用于接口的ContainerDependencyMetaData:au.com.purejet.action.TestBeanServiceInterface 

导致:java.lang.IllegalStateException:无法找到接口的ContainerDependencyMetaData:com.mydomain.action.TestBeanServiceInterface
在org.jboss.deployment.MappedReferenceMetaDataResolverDeployer.resolveEjbInterface(MappedReferenceMetaDataResolverDeployer.java:1255)[:6.0.0.Final]
在org.jboss.deployment.MappedReferenceMetaDataResolverDeployer .resolveEjbRefs(MappedReferenceMetaDataResolverDeployer.java:1099)[:6.0.0.Final]
在org.jboss.deployment.MappedReferenceMetaDataResolverDeployer.resolve(MappedReferenceMetaDataResolverDeployer.java:807)[:6.0.0.Final]
在org.jboss.deployment.MappedReferenceMetaDataResolverDeployer.internalDeploy(MappedReferenceMetaDataResolverDeployer.java:181)[:6.0.0.Final]
... 39更多






更新:



本地界面工作很好(即不必是远程的)



我通过在Eclipse中的企业应用程序项目中部署来实现它。在web.xml,ejb-jar.xml或application.xml中不需要引用bean。



EAR中的application.xml内容正在部署到Jboss中: / p>

 <?xml version =1.0encoding =UTF-8?> 
< application xmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexmlns =http://java.sun.com/xml/ns/javaeexmlns:application =http://java.sun.com/xml/ns/javaee/application_5.xsdxsi:schemaLocation =http://java.sun.com/xml/ns/javaee http://java.sun。 com / xml / ns / javaee / application_6.xsdid =Application_IDversion =6>
< display-name> myprojects< / display-name>
< module>
< web>
< web-uri> myproject.war< / web-uri>
< context-root> myproject< / context-root>
< / web>
< / module>
< module>
< ejb> myprojectsEJB.jar< / ejb>
< / module>
< / application>

SessionBean类:

 public $ _ 

public class SessionBean实现SessionBeanLocal {

@PersistenceContext(unitName =JPAtestProjectPersistenceUnit)
private EntityManager em;

接口类:

  @Local 
public interface SessionBeanLocal {

TestTiger addTestTiger(String testTigerName);

最重要的改变,使事情工作:持有会话的类内部是局部变量,设置是容器(JBoss AS)创建bean所必需的:

  @EJB()
private TestBean3Local beanVariable;

public void setBeanVariable(TestBean3Local beanVariable){
System.out.println(===== \\\
\\\
SET BEAN VARIABE SETTER WAS CALLED。(by CONTAINER?)\\ \
\\\
=======);
this.beanVariable = beanVariable;
}


解决方案

我已经获得了一个工作解决方案:



@Local界面工作正常(即不必为Remote)



bean在web.xml,ejb-jar.xml,application.xml或任何jboss配置文件中都是必需的。



我通过在企业应用程序项目(EAP)。此项目包含部署程序集,其中包含包含JPA实体类的.jar以及包含其他业务逻辑类的另一个.jar。 EAP有这两个项目加上EJB项目和动态Web项目(创建一个.war),共有4个项目在其构建路径上。 Eclipse中的Jboss AS工具将EAP发布/部署到Jboss服务器。正在部署到Jboss的EAP内的application.xml的内容:

 <?xml version =1.0encoding =UTF- 8\" >?; 
< application xmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexmlns =http://java.sun.com/xml/ns/javaeexmlns:application =http://java.sun.com/xml/ns/javaee/application_5.xsdxsi:schemaLocation =http://java.sun.com/xml/ns/javaee http://java.sun。 com / xml / ns / javaee / application_6.xsdid =Application_IDversion =6>
< display-name> myprojects< / display-name>
< module>
< web>
< web-uri> myproject.war< / web-uri>
< context-root> myproject< / context-root>
< / web>
< / module>
< module>
< ejb> myprojectsEJB.jar< / ejb>
< / module>
< / application>

本地界面类:

  package com.myproject.beans; 
import javax.ejb.Local;

import com.myproject.entities.Lion;

@Local
public interface SessionBeanLocal {
Lion addLion(String lionName);
}

SessionBean类:

  package com.myproject.beans; 

import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.myproject.Lion;

@Stateless
@Local(SessionBeanLocal.class)
public class SessionBean实现SessionBeanLocal {

@PersistenceContext(unitName =PersistenceUnitNameInPersistenceXML)
private EntityManager em;

public Lion addLion(String lionName){
狮子狮=新狮子(lionName);
em.persist(lion);
}

最重要的改变让事情发生:持有会话的课程内变量(例如在Struts操作servlet中,但可以是任何servlet),容器(JBoss AS)需要一个setter方法来创建bean:

  @EJB()
private SessionBeanLocal bean;

public void setBean(SessionBeanLocal bean){
System.out.println(setBean setter被容器调用(例如Jboss));
this.bean = bean;
}

public exampleStrutsServletMethod(ActionMapping映射,ActionForm形式,HttpServletRequest请求,HttpServletResponse响应)throws异常{
PrintWriter out = response.getWriter();

狮子狮= bean.addLion(Simba); //这将使持久化上下文中的Lion(并自动生成一个Id),并且容器在刷新到数据库时将被管理

out.print(< html> LION ID =+ lion.getLionId()+< html>);
}

file persistnce.xml:

 <?xml version =1.0encoding =UTF-8?> 
< persistence xmlns =http://java.sun.com/xml/ns/persistencexmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexsi:schemaLocation =http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsdversion =2.0>
< persistence-unit name =PersistenceUnitNameInPersistenceXMLtransaction-type =JTA>
< provider> org.hibernate.ejb.HibernatePersistence< / provider>
< jta-data-source> java:/ MySqlDS< / jta-data-source>
<属性>
< / properties>
< / persistence-unit>



mysql-dx.xml(在目录jboss-server-dir / server / default / deploy中):

 <?xml version =1.0encoding = UTF-8 >?; 
< datasources>
< local-tx-datasource>
< jndi-name> MySqlDS< / jndi-name>
< connection-url> jdbc:mysql:// localhost:3306 / myProjectDatabase< / connection-url>
< driver-class> com.mysql.jdbc.Driver< / driver-class>
< user-name> username< / user-name>
< password> mypassword< / password>
< exception-sorter-class-name> org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter< / exception-sorter-class-name>
< metadata>
< type-mapping> mySQL< / type-mapping>
< / metadata>
< / local-tx-datasource>
< / datasources>

注意:不需要在persistence.xml中定义类(通过< class> )如果持久性类管理在Eclipse JPA项目的Java Persistence项目属性面板中设置为发现注释类(即容纳您的JPA 2.0 Entity类和persistence.xml的项目)



注意:此解决方案基于:EJB3.1,Eclipse Helios SR2,Hibernate 3.6,JPA 2.0,JBoss 6,MySQL 5.5.10



注意:关于集装箱管理事务(CMT)。 Hibernate手册引用它们,并指出您需要将persistence.xml属性(如hibernate.transaction.factory_class)设置为org.hibernate.transaction.CMTTransactionFactory的值。如果您使用JPA EntityManager而不是本机hibernate,则不是这样。在persistence.xml中我没有要求任何这样的自定义CMT属性。这是Hibernate在两种实现方式(即SessionFactory vs EntityManager)之间变得混乱的地方。请随时对我的这个解决方案进行更多的评论,因为我仍然围绕着我的头脑!将


I was trying to get CMT working with JPA EntityManagers and EJBs, but came up with the error below. (stack trance truncated):

Caused by: java.lang.RuntimeException: **Could not resolve @EJB reference: [EJB Reference: beanInterface 'com.mydomain.beans.TestBean2', beanName 'testBean2', mappedName 'null', lookupName 'null',** owning unit 'AbstractVFSDeploymentContext@2008455195{vfs:///Users/willtardy/Documents/workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.0_Runtime_Server1300532851414/deploy/mydomainWeb.war}']
for environment entry: env/com.mydomain.action.SearchAction/testBean in unit AbstractVFSDeploymentContext@2008455195{vfs:///Users/willtardy/Documents/workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.0_Runtime_Server1300532851414/deploy/mydomainWeb.war}

My classes:

Servlet that access the Session Bean:

public class SearchActionExample extends Action {
    @EJB
    private static TestBeanServiceInterface testBean;

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        testBean.addSource("TEST SOURCE NAME", 88, 99);
        Service service = testBean.findService("HBA", "MEL");

        return mapping.findForward("success");
    }
}

Remote interface:

@Remote
public interface TestBeanServiceInterface {
    // Source is my own custom entity
    void addSource(String sourceName, int newthreadsleeptime, int maxactivehttpclients);

    // Service is my own Custom entity    
    Service findService(String departureAirportCode, String arrivalAirportCode);
}

Stateless Session Bean definition:

@Stateless
public class TestBeanService implements TestBeanServiceInterface {

    @PersistenceContext(unitName="mydomainJPA")
    private EntityManager em;

    public void addSource(String sourceName, int newthreadsleeptime, int maxactivehttpclients) {
        Source source = new Source();
        source.setName(sourceName);
        source.setNewThreadSleepTime(newthreadsleeptime);
        source.setMaxActiveHttpClients(maxactivehttpclients);
        em.persist(source);
    }
    public Service findService(String departureAirportCode, String arrivalAirportCode) {
        String queryString = "from Service where departureairportcode = '" + departureAirportCode + "' and arrivalairportcode = '" + arrivalAirportCode + "'";
        Service service = (Service)em.createQuery(queryString).getSingleResult();
        return service;
    }
}

file persistnce.xml:

<?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_2_0.xsd" version="2.0">
<persistence-unit name="mydomainJPA" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:/MySqlDS</jta-data-source>
    <class>com.mydomain.entities.Service</class>
<class>com.mydomain.entities.Source</class>
    <properties>
        <property name="hibernate.query.factory_class" value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>
        <property name="hibernate.archive.autodetection" value="class"/>
        <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
        <property name="hibernate.current_session_context_class" value="jta"/>   
    </properties>   
</persistence-unit>

When it says "cannot resolve reference", where else can I define the beans? ejb-jar.xml isn't needed with EJB3. Is there some other config file that I'm missing?


UPDATE:

  • I have updated the code segments above so that the bean is created as the interface type instead, as per the answer below.

  • Do the EJBs need to be defined or mapped in web.xml?

  • Assuming that a reference is required in web.xml, I have added an EJB ref to web.xml (see below), but now I'm receiving a new error (see below)

lines added to web.xml:

<ejb-ref>
    <ejb-ref-name>ejb/TestBeanEJBname</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <home>com.mydomain.action.TestBeanService</home>
    <remote>com.mydomain.action.TestBeanServiceInterface</remote>
 </ejb-ref>

new error message now being received:

12:11:00,980 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] Error installing to PostClassLoader: name=vfs:///Users/willtardy/Documents/workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.0_Runtime_Server1300532851414/deploy/purejetWeb.war state=ClassLoader mode=Manual requiredState=PostClassLoader: org.jboss.deployers.spi.DeploymentException: java.lang.IllegalStateException: Failed to find ContainerDependencyMetaData for interface: au.com.purejet.action.TestBeanServiceInterface

Caused by: java.lang.IllegalStateException: Failed to find ContainerDependencyMetaData for interface: com.mydomain.action.TestBeanServiceInterface
at org.jboss.deployment.MappedReferenceMetaDataResolverDeployer.resolveEjbInterface(MappedReferenceMetaDataResolverDeployer.java:1255) [:6.0.0.Final]
at org.jboss.deployment.MappedReferenceMetaDataResolverDeployer.resolveEjbRefs(MappedReferenceMetaDataResolverDeployer.java:1099) [:6.0.0.Final]
at org.jboss.deployment.MappedReferenceMetaDataResolverDeployer.resolve(MappedReferenceMetaDataResolverDeployer.java:807) [:6.0.0.Final]
at org.jboss.deployment.MappedReferenceMetaDataResolverDeployer.internalDeploy(MappedReferenceMetaDataResolverDeployer.java:181) [:6.0.0.Final]
... 39 more


Update:

"Local" interface works just fine (i.e. doesn't have to be Remote)

I got it to work by deploying within an Enterprise Application Project within Eclipse. No references to beans are required within web.xml, ejb-jar.xml, or application.xml.

Contents of application.xml within EAR being deployed to Jboss:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" id="Application_ID" version="6">
<display-name>myprojects</display-name>
<module>
<web>
<web-uri>myproject.war</web-uri>
<context-root>myproject</context-root>
</web>
</module>
<module>
<ejb>myprojectsEJB.jar</ejb>
</module>
</application>

SessionBean class:

@Stateless
@Local(SessionBeanLocal.class)

public class SessionBean implements SessionBeanLocal {

@PersistenceContext(unitName="JPAtestProjectPersistenceUnit")
private EntityManager em;

Interface class:

@Local
public interface SessionBeanLocal {

TestTiger addTestTiger(String testTigerName);

MOST IMPORTANT change that got things working: inside the class that holds the session been local variable, a setting was required for the container (JBoss AS) to create the bean:

@EJB()
private TestBean3Local beanVariable;

public void setBeanVariable(TestBean3Local beanVariable) {
    System.out.println("=====\n\nSET BEAN VARIABE SETTER WAS CALLED. (BY CONTAINER?)  \n\n=======");
    this.beanVariable = beanVariable;
}

解决方案

I have obtained a working solution:

@Local interface works just fine (i.e. doesn't have to be Remote)

No references to beans are required within web.xml, ejb-jar.xml, application.xml, or any jboss config file.

I got it to work by deploying within an "Enterprise Application Project" (EAP) within Eclipse. This project contains "Deployment Assembly" that contains the .jar containing JPA Entity Classes, and another .jar that contains other business-logic classes. The EAP has those two projects PLUS the EJB project and the "Dynamic Web Project" (creates a .war) for a total of 4 projects on it's build path. Jboss AS tool within Eclipse publishes/deploys the EAP to the Jboss server. Contents of application.xml within EAP being deployed to Jboss:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" id="Application_ID" version="6">
    <display-name>myprojects</display-name>
    <module>
        <web>
            <web-uri>myproject.war</web-uri>
            <context-root>myproject</context-root>
        </web>
    </module>
    <module>
        <ejb>myprojectsEJB.jar</ejb>
    </module>
</application>

Local Interface class:

package com.myproject.beans;
import javax.ejb.Local;

import com.myproject.entities.Lion;

@Local
public interface SessionBeanLocal {
Lion addLion(String lionName);
}

SessionBean class:

package com.myproject.beans;

import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.myproject.Lion;

@Stateless
@Local(SessionBeanLocal.class)
public class SessionBean implements SessionBeanLocal {

@PersistenceContext(unitName="PersistenceUnitNameInPersistenceXML")
private EntityManager em;

public Lion addLion(String lionName) {
    Lion lion = new Lion(lionName);
    em.persist(lion);
}

MOST IMPORTANT change that got things working: inside the class that holds the session been variable (e.g. inside a Struts action servlet, but could be any servlet), a setter method was required for the container (JBoss AS) to create the bean:

@EJB()
private SessionBeanLocal bean;

public void setBean(SessionBeanLocal bean) {
    System.out.println("setBean setter was called by container (e.g. Jboss)");
    this.bean = bean;
}

public exampleStrutsServletMethod(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    PrintWriter out = response.getWriter();

    Lion lion = bean.addLion("Simba");  // this will persist the Lion within the persistence-context (and auto-generate an Id), and the container will manage when it's flushed to the database

    out.print("<html>LION ID = " + lion.getLionId() + "<html>");
}

file persistnce.xml:

<?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_2_0.xsd" version="2.0">
<persistence-unit name="PersistenceUnitNameInPersistenceXML" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:/MySqlDS</jta-data-source>
    <properties>
    </properties>   
</persistence-unit>

mysql-dx.xml (in directory jboss-server-dir/server/default/deploy):

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
    <local-tx-datasource>
        <jndi-name>MySqlDS</jndi-name>
        <connection-url>jdbc:mysql://localhost:3306/myProjectDatabase</connection-url>
        <driver-class>com.mysql.jdbc.Driver</driver-class>
        <user-name>username</user-name>
        <password>mypassword</password>
        <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
        <metadata>
            <type-mapping>mySQL</type-mapping>
        </metadata>
    </local-tx-datasource>
</datasources>

NOTE: Classes do not need to be defined in persistence.xml (via "< class >") if "Persistence Class Management" is set to "Discover annotated classes automatically" in "Java Persistence" project property panel for the Eclipse JPA project (i.e. the project that containers your JPA 2.0 Entity classes and persistence.xml)

NOTE: This solution is based on: EJB3.1, Eclipse Helios SR2, Hibernate 3.6, JPA 2.0, JBoss 6, MySQL 5.5.10

NOTE: Regarding "Container Managed Transactions" (CMT). The Hibernate manual references them, and indicates that you need to set persistence.xml properties such as "hibernate.transaction.factory_class" to value of: "org.hibernate.transaction.CMTTransactionFactory". This is not the case if you are using JPA EntityManager instead of native hibernate. I didn't required any such custom CMT properties in persistence.xml. This is where Hibernate gets confusing, between the two ways to implement it (i.e. SessionFactory vs EntityManager). Please feel free to comment more on this part of my solution as I'm still just wrapping my head around it! Will

这篇关于如何获取使用EJB 3.1,Hibernate 3.6,JPA 2.0,JBoss和MySQL的容器管理事务(CMT)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆