gpt4 book ai didi

java - PersistenceUnitInfo [appName] 有事务类型 JTA,但没有定义 jtaDataSource

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:46:55 26 4
gpt4 key购买 nike

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

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

我将 Hibernate 4.2.8 用于持久性,将 Spring MVC 4.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.

我正在使用基于 Hibernate 配置文件的 Spring 注解。

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());
}

}

我的 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>

你们中的任何人都可以帮助我让它工作吗?我感谢所有帮助。谢谢!

更新

我执行了以下操作以将其切换为 JTA:

  • 在 Hibernate java 配置文件中添加了一个 JtaTransactionManager 而不是使用 HibernateTransactionManager。
  • 在 LocalSessionFactoryBean 中设置 JtaTransactionManager 属性
  • 在 spring-servlet 文件中添加了一个 jdni 查找
  • 在 web.xml 和 weblogic.xml 文件中添加了资源引用
  • 删除了spring-servlet中的数据源,并删除了hibernate java配置文件中对它的引用
  • 在服务器上创建了一个数据源

虽然仍然没有 100% 工作。将保持更新。

更新:这是我一直在使用的有用资源 ( http://spring.io/blog/2011/08/15/configuring-spring-and-jta-without-full-java-ee/ )

最佳答案

您还没有发布您的 persistence.xml JPA 配置文件,但它可能包含如下内容:

<persistence-unit name="..." transaction-type="JTA">
<jta-data-source>java:/DefaultDS</jta-data-source>

在应用服务器上部署时,您应该受益于它们自己的 JTA 数据源和事务管理器支持,因此通过 JNDI 定位 jtaDataSource 应该是您的第一选择。

你的数据源是用Spring配置的:

org.springframework.jdbc.datasource.DriverManagerDataSource

这并不是真正的生产就绪数据源实现。

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

关于java - PersistenceUnitInfo [appName] 有事务类型 JTA,但没有定义 jtaDataSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23764528/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com