Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java PersistenceUnitInfo[appName]具有transactionType JTA,但未定义jtaDataSource_Java_Spring_Hibernate_Jpa_Transactions - Fatal编程技术网

Java PersistenceUnitInfo[appName]具有transactionType JTA,但未定义jtaDataSource

Java PersistenceUnitInfo[appName]具有transactionType JTA,但未定义jtaDataSource,java,spring,hibernate,jpa,transactions,Java,Spring,Hibernate,Jpa,Transactions,我不熟悉WebLogic,也不熟悉Hibernate/Spring应用程序,因为我的主要语言是C#,我的主要服务器一直是Windows服务器,所以请原谅我可能遇到的任何简单错误 我在部署到WebLogic 10.3.4服务器时遇到问题。它在本地WebLogic实例上工作,但在远程服务器上不工作 我将Hibernate4.2.8用于持久性,SpringMVC4.0用于我的web应用程序框架。我收到的错误是: Failed to load webapp: 'ncms2_May20.war' Mes

我不熟悉WebLogic,也不熟悉Hibernate/Spring应用程序,因为我的主要语言是C#,我的主要服务器一直是Windows服务器,所以请原谅我可能遇到的任何简单错误

我在部署到WebLogic 10.3.4服务器时遇到问题。它在本地WebLogic实例上工作,但在远程服务器上不工作

我将Hibernate4.2.8用于持久性,SpringMVC4.0用于我的web应用程序框架。我收到的错误是:

Failed to load webapp: 'ncms2_May20.war'

Message icon - Error Substituted for missing class Exception [EclipseLink-28010] (Eclipse Persistence Services - 2.1.2.v20101206-r8635) - org.eclipse.persistence.exceptions.EntityManagerSetupException Exception Description: PersistenceUnitInfo ncms2 has transactionType JTA, but does not have a jtaDataSource defined.
我使用的是基于Spring注释的Hibernate配置文件

package mil.navy.navsupbsc.utilities;

import java.util.Properties;

import javax.sql.DataSource;

import com.app.AuditInterceptor;

import org.hibernate.SessionFactory;
import org.hibernate.dialect.Oracle10gDialect;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;

@Configuration
public class HibernateConfiguration {

    @Value("#{dataSource}")
    private DataSource dataSource;


    @Bean
    public LocalSessionFactoryBean sessionFactoryBean() {
        Properties props = new Properties();
        props.put("hibernate.dialect", Oracle10gDialect.class.getName());
        props.put("hibernate.format_sql", "true");
        props.put("hibernate.hbm2ddl.auto", "update");
        props.put("hibernate.show_sql", "true");
        props.put("hibernate.format_sql", "true");
        props.put("hibernate.use_sql_comments", "true");
        LocalSessionFactoryBean bean = new LocalSessionFactoryBean();
        bean.setEntityInterceptor(new AuditInterceptor());
        bean.setPackagesToScan(new String[] { "com.app.entity" });           
                bean.setHibernateProperties(props);     
        bean.setDataSource(this.dataSource);

        return bean;
    }

    @Bean
    public HibernateTransactionManager transactionManager() {
        return new HibernateTransactionManager(sessionFactoryBean().getObject());
    }

}
<?xml  version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:c="http://www.springframework.org/schema/c"
    xmlns:cache="http://www.springframework.org/schema/cache" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:task="http://www.springframework.org/schema/task" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages" />
        <property name="defaultEncoding" value="UTF-8" />
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="packagesToScan" value="mil.navy.navsupbsc.entity" />
        <property name="dataSource" ref="NCS"/>
        <property name="jtaTransactionManager" ref="transactionManager" />

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform
                </prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <prop key="hibernate.driverClassName">oracle.jdbc.OracleDriver</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.use_sql_comments">true</prop>
            </props>
        </property>
    </bean>

    <mvc:annotation-driven />

    <mvc:resources mapping="/resources/**" location="/resources/" />
    <context:component-scan base-package="mil.navy.navsupbsc" />
    <tx:annotation-driven transaction-manager="transactionManager" />
    <jee:jndi-lookup id="NCS" jndi-name="NCS" resource-ref="false">
    </jee:jndi-lookup>
    <tx:jta-transaction-manager id="transactionManager" />
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>
                org.springframework.web.servlet.view.tiles2.TilesView
            </value>
        </property>
    </bean>
    <bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles.xml</value>
            </list>
        </property>
    </bean>

</beans>
我的Spring Servlet XML:

    <?xml  version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:c="http://www.springframework.org/schema/c"
    xmlns:cache="http://www.springframework.org/schema/cache" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:task="http://www.springframework.org/schema/task" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages" />
        <property name="defaultEncoding" value="UTF-8" />
    </bean>
    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
        p:location="/WEB-INF/jdbc.properties" />

    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource"
        p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.databaseurl}"
        p:username="${jdbc.username}" p:password="${jdbc.password}" />
    <mvc:annotation-driven />
    <tx:annotation-driven transaction-manager="transactionManager" />
    <mvc:resources mapping="/resources/**" location="/resources/" />
    <context:component-scan base-package="com.app" />

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>
                org.springframework.web.servlet.view.tiles2.TilesView
            </value>
        </property>
    </bean>
    <bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles.xml</value>
            </list>
        </property>
    </bean>

</beans>

org.springframework.web.servlet.view.tiles2.TilesView
/WEB-INF/tiles.xml
你们谁能帮我把这件事做好吗?我感谢所有的帮助。谢谢大家!

更新

我做了以下操作将其切换到JTA:

  • 在Hibernate java配置文件中添加了JtaTransactionManager,而不是使用HibernateTransactionManager
  • 在LocalSessionFactoryBean中设置JtaTransactionManager属性
  • 在SpringServlet文件中添加了jdni查找
  • 在web.xml和weblogic.xml文件中添加了资源引用
  • 删除了SpringServlet中的数据源,并删除了HibernateJava配置文件中对它的引用
  • 在服务器上创建了一个数据源
但仍然无法100%工作。将保持此更新


更新:这里有一个我一直在使用的有用资源()

您尚未发布persistence.xml JPA配置文件,但它可能包含以下内容:

<persistence-unit name="..." transaction-type="JTA">
<jta-data-source>java:/DefaultDS</jta-data-source>
这并不是一个真正的生产就绪的数据源实现


因此,请尝试配置您的Spring应用程序上下文,以利用WebLogic事务管理支持。

我使用@Vlad Mihalcea在回答中给出的信息来改进代码;然而,这并不是它不起作用的原因。@Vlad的一条评论建议在META-INF文件夹中查找persistence.xml文件,这让我得到了答案

尽管我使用的是Hibernate的Spring配置文件,但在META-INF文件夹下有一个旧的persistence.xml文件。我没有使用它,但WebLogic会自动拾取它。因为我没有使用它,所以persistence.xml文件中没有指定数据源。如果未指定为
RESOURCE LOCAL
,WebLogic会自动假定任何持久化单元都是JTA。我删除了persistence.xml文件,它成功了

也就是说,我还按照@Vlad Mihalcea的建议修改了使用JTA数据源的代码。我将所有配置代码移到Spring-servlet.xml文件中,以简化配置。我相信它可以被翻译成程序化的Spring配置,而不会有太多麻烦

同时,这里是一个基于JTA事务的Spring/Hibernate配置文件

package mil.navy.navsupbsc.utilities;

import java.util.Properties;

import javax.sql.DataSource;

import com.app.AuditInterceptor;

import org.hibernate.SessionFactory;
import org.hibernate.dialect.Oracle10gDialect;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;

@Configuration
public class HibernateConfiguration {

    @Value("#{dataSource}")
    private DataSource dataSource;


    @Bean
    public LocalSessionFactoryBean sessionFactoryBean() {
        Properties props = new Properties();
        props.put("hibernate.dialect", Oracle10gDialect.class.getName());
        props.put("hibernate.format_sql", "true");
        props.put("hibernate.hbm2ddl.auto", "update");
        props.put("hibernate.show_sql", "true");
        props.put("hibernate.format_sql", "true");
        props.put("hibernate.use_sql_comments", "true");
        LocalSessionFactoryBean bean = new LocalSessionFactoryBean();
        bean.setEntityInterceptor(new AuditInterceptor());
        bean.setPackagesToScan(new String[] { "com.app.entity" });           
                bean.setHibernateProperties(props);     
        bean.setDataSource(this.dataSource);

        return bean;
    }

    @Bean
    public HibernateTransactionManager transactionManager() {
        return new HibernateTransactionManager(sessionFactoryBean().getObject());
    }

}
<?xml  version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:c="http://www.springframework.org/schema/c"
    xmlns:cache="http://www.springframework.org/schema/cache" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:task="http://www.springframework.org/schema/task" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages" />
        <property name="defaultEncoding" value="UTF-8" />
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="packagesToScan" value="mil.navy.navsupbsc.entity" />
        <property name="dataSource" ref="NCS"/>
        <property name="jtaTransactionManager" ref="transactionManager" />

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform
                </prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <prop key="hibernate.driverClassName">oracle.jdbc.OracleDriver</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.use_sql_comments">true</prop>
            </props>
        </property>
    </bean>

    <mvc:annotation-driven />

    <mvc:resources mapping="/resources/**" location="/resources/" />
    <context:component-scan base-package="mil.navy.navsupbsc" />
    <tx:annotation-driven transaction-manager="transactionManager" />
    <jee:jndi-lookup id="NCS" jndi-name="NCS" resource-ref="false">
    </jee:jndi-lookup>
    <tx:jta-transaction-manager id="transactionManager" />
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>
                org.springframework.web.servlet.view.tiles2.TilesView
            </value>
        </property>
    </bean>
    <bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles.xml</value>
            </list>
        </property>
    </bean>

</beans>

org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform
更新
org.hibernate.dialen.oracle10galent
oracle.jdbc.OracleDriver
真的
真的
真的
org.springframework.web.servlet.view.tiles2.TilesView
/WEB-INF/tiles.xml

请注意,我还需要将web.xml和WebLogic.xml文件中的引用添加到我在web服务器上创建的JNDI数据源(在我的应用程序中称为NCS)。

如果您使用的是Hibernate,为什么您的错误消息会引用eclipse链接?我不知道-我在应用程序中的任何内容中都没有提及EclipseLink,虽然我知道EclipseLink安装在服务器上。这就是为什么我真的很困惑。由于我没有使用它,我不知道该在应用程序中更改什么…可能是服务器配置问题?好的-我想我理解这个概念-我将致力于实现它,并希望它能正常工作-我假设它与创建WebLogicJtaTransactionManager类似?关于如何做到这一点,有什么好的资源建议吗?我现在正在看一些Spring文档(),但它是针对旧版本的Spring的。这可能会对您有所帮助。我很快阅读了它,我将再次阅读它以获取相关信息,但它指的是较低版本的Spring,并且没有使用注释或包扫描的自动连接。不过,这对理解概念很有帮助,所以谢谢!Spring 4.0.x仍然包含。TransactionProxyFactoryBean被@Transactional注释替换,该注释应应用于您的服务方法。还有一点,Persistence.xml是JPA的一项要求。春天不能代替它。您的问题名称是JPA异常,因此您从某处继承persistence.xml。检查jars/META-INF文件夹内部。做得好,劳拉!感谢您发布最终配置。其他遇到麻烦的人肯定会发现它很有用。我很高兴它终于被解决了!这是令人沮丧的,但在我的腰带下获得更多的知识是很好的。希望它能为其他人省去一些麻烦。非常感谢您的帮助:)