简体   繁体   中英

How can i defind <non-jta-data-source> </non-jta-data-source> in persistence.xml?

How can i define <non-jta-data-source> </non-jta-data-source> in persistence.xml?

My project runs well in Tomcat 6 and Tomcat 7.

now i am using

  1. Struts 2
  2. Spring 3.0.5
  3. JPA 2
  4. Jboss 6

my persistence.xml looks likes this

       <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" 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">
    <persistence-unit name="axw-db" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    **<non-jta-data-source></non-jta-data-source>**
    <properties>
     <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
    <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
    <property name="hibernate.connection.username" value="root"/>
    <property name="hibernate.connection.password" value="root"/>
    <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/abc"/>
    <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
    <property name="hibernate.ejb.autodetection" value="class"/>
    </properties>
    </persistence-unit>
    </persistence>

now i am getting this exception

[org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/icc-web-struts2-1.0.0-SNAPSHOT]] Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in URL [vfs:/D:/workspace/icc-temp/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1319268021951/deploy/icc-web-struts2.war/WEB-INF/lib/icc-core.jar/core-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [vfs:/D:/workspace/icc-temp/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1319268021951/deploy/icc-web-struts2.war/WEB-INF/lib/icc-core.jar/core-config.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: error trying to scan : vfs:/D:/workspace/icc-temp/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1319268021951/deploy/icc-web-struts2.war/WEB-INF/lib/icc-domain.jar/

The non-jta-data-source is used to define a datasource which doesn't use the existing JTA manager. If you're interested exactly in this feature, than it accepts the JNDI location of the non-JTA data source (ie java:app/jdbc/yourNonJTAsource ).

The Datasource should be configured in your application server and this configuration is vendor-specific. Try accessing the JBoss web admin console and create/define the Pool/Datasource there. If that's the case, than you can get rid of those user/password/url/... stuff from your persistence.xml as these information will be moved to the Application Server.

If you're using this persistence.xml totally outside of the container, than you probably don't need the non-jta nor the jta datasources, as you cannot rely on the JNDI outside the container.

HTH.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM