gpt4 book ai didi

java - Spring JPA TransactionManager 未找到

转载 作者:行者123 更新时间:2023-12-01 05:13:29 26 4
gpt4 key购买 nike

我有一个我认为是简单的项目,其中我使用 Spring 来管理 JPA,并使用 EclipseLink 作为我的持久性单元。我在前端使用 JavaFX,并将项目分为客户端模块、公共(public)模块和服务器模块。我正在使用 Maven 进行构建。这几天我一直在用头撞墙,试图弄清楚这一点。我尝试了不同的持久性单元配置和 servlet 配置,但似乎没有任何效果。而且错误似乎总是非常相似:事务管理器配置或使用中的某些内容值得怀疑。

非常感谢所有帮助。我是 Spring JPA 领域的新手,如果问题没有得到充分定义,请原谅。

这是我的 pom:

<project xmlns="http://maven.apache.org/POM/4.0.0"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.lamtec</groupId>
<artifactId>NewTrialServer</artifactId>
<version>1.0</version>
<packaging>war</packaging>

<name>NewTrialServer</name>
<!-- Spring Web MVC -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>unknown-jars-temp-repo</id>
<name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
<url>file:${project.basedir}/lib</url>
</repository>
<repository>
<url>http://download.eclipse.org/rt/eclipselink/maven.repo/</url>
<id>eclipselink</id>
<layout>default</layout>
<name>Repository for library EclipseLink (JPA 2.0)</name>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.lamtec</groupId>
<artifactId>NewTrialCommon</artifactId>
<version>1.0</version>
</dependency>

<!-- Spring Web MVC -->

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>

<!-- Spring data -->

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.0.2.RELEASE</version>
</dependency>

<!-- JPA -->

<dependency>
<groupId>org.hibernate.java-persistence</groupId>
<artifactId>jpa-api</artifactId>
<version>2.0-cr-1</version>
</dependency>

<!-- Hibernate -->

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.8.Final</version>
</dependency>

<!-- HSQL DB -->

<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.10</version>
</dependency>

<!-- Injection framework -->

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.3.2</version>
<scope>provided</scope>
</dependency>
</dependencies>

这是我的 persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="NewTrialsPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>NewTrials</jta-data-source>
<class>com.lamtec.newtrial.service.Trial</class>
<class>com.lamtec.newtrial.service.TrialCtWtCheck</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>

这是我的 servlet:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:data="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<context:annotation-config/>
<context:component-scan base-package="com.lamtec"/>

<bean name="trialServiceImpl" class="com.lamtec.newtrial.service.TrialServiceImpl"/>

<bean name="/new-trial.service" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service" ref="trialServiceImpl"/>
<property name="serviceInterface" value="com.lamtec.newtrial.service.TrialService"/>
</bean>

<!-- Database Setup -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="NewTrialsPU" />
</bean>
<data:repositories base-package="com.lamtec.newtrial.service.repository"/>

<!-- Transaction Setup -->
<tx:annotation-driven/>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

我有两个实体类,试用:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.lamtec.newtrial.service;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;


@Entity
@Table(name = "Trial")
public class Trial implements Serializable{
private static final long serialVersionUID = 1L;
// @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
@Id
@Basic(optional = false)
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "TRIAL_ID")
private Long trial_Id;
@Column(name = "AUX_ADHESIVE1_WEIGHT")
private String auxAdhesive1Weight;
@Column(name = "AUX_ADHESIVE2_WEIGHT")
private String auxAdhesive2Weight;
@Column(name = "AUX_ADHESIVE_1")
private String auxAdhesive1;
@Column(name = "AUX_ADHESIVE_2")
private String auxAdhesive2;
@Column(name = "CT_WT_RANGE")
private String ctWtRange;
@Column(name = "DRIVE")
private String drive;
@Column(name = "DRIVE_WEIGHT")
private String driveWeight;
@Column(name = "FINISH_WT_ACCEPTABLE_RANGE")
private String finishWtAcceptableRange;
@Basic(optional = false)
@Column(name = "LAMINATOR")
private String laminator;
@Column(name = "LOWER_ADHESIVE")
private String lowerAdhesive;
@Column(name = "LOWER_ADHESIVE_WEIGHT")
private String lowerAdhesiveWeight;
@Column(name = "LOWER_AUX_WEIGHT")
private String lowerAuxWeight;
@Column(name = "LOWER_AUXILLIARY")
private String lowerAuxilliary;
@Column(name = "LOWER_UNWIND")
private String lowerUnwind;
@Column(name = "LOWER_UNWIND_WEIGHT")
private String lowerUnwindWeight;
@Column(name = "TARGET_CT_WEIGHT")
private String targetCtWeight;
@Column(name = "TARGET_TOTAL_FINISHED_WEIGHT")
private String targetTotalFinishedWeight;
@Column(name = "TRIAL_DATE")
private String trialDate;
@Basic(optional = false)
@Column(name = "TRIALNO")
private String trialno;
@Lob
@Column(name = "TRIAL_NOTES")
private String trialNotes;
@Column(name = "TRIAL_START_TIME")
private String trialStartTime;
@Column(name = "UPPER_ADHESIVE")
private String upperAdhesive;
@Column(name = "UPPER_ADHESIVE_WEIGHT")
private String upperAdhesiveWeight;
@Column(name = "UPPER_AUX_WEIGHT")
private String upperAuxWeight;
@Column(name = "UPPER_AUXILLIARY")
private String upperAuxilliary;
@Column(name = "UPPER_UNWIND")
private String upperUnwind;
@Column(name = "UPPER_UNWIND_WEIGHT")
private String upperUnwindWeight;
@Column(name = "YARN")
private String yarn;
@Column(name = "YARN_WEIGHT")
private String yarnWeight;
@OneToMany(cascade={CascadeType.ALL}, mappedBy="trialId", targetEntity=TrialCtWtCheck.class, fetch= FetchType.EAGER)
// @JoinColumn(name="ID")
private List<TrialCtWtCheck> trialCtWtCheckList;
public List<TrialCtWtCheck> getTrialCtWtCheckList() {
return trialCtWtCheckList;
}

public void setTrialCtWtCheckList(List<TrialCtWtCheck> trialCtWtCheckList) {
this.trialCtWtCheckList = trialCtWtCheckList;
}


public Trial() {
super();
}

public Trial(Trial t) {
// this.trial_Id = t.getTrialId();
this.auxAdhesive1Weight = t.getAuxAdhesive1Weight();
this.auxAdhesive2Weight = t.getAuxAdhesive2Weight();
this.auxAdhesive1 = t.getAuxAdhesive1();
this.auxAdhesive2 = t.getAuxAdhesive2();
this.ctWtRange = t.getCtWtRange();
this.drive = t.getDrive();
this.driveWeight = t.getDriveWeight();
this.finishWtAcceptableRange = t.getFinishWtAcceptableRange();
this.laminator = t.getLaminator();
this.lowerAdhesive = t.getLowerAdhesive();
this.lowerAdhesiveWeight = t.getLowerAdhesiveWeight();
this.lowerAuxWeight = t.getLowerAuxWeight();
this.lowerAuxilliary = t.getLowerAuxilliary();
this.lowerUnwind = t.getLowerUnwind();
this.lowerUnwindWeight = t.getLowerUnwindWeight();
this.targetCtWeight = t.getTargetCtWeight();
this.targetTotalFinishedWeight = t.targetTotalFinishedWeight;
this.trialDate = t.getTrialDate();
this.trialno = t.getTrialno();
this.trialNotes = t.getTrialNotes();
this.trialStartTime = t.getTrialStartTime();
this.upperAdhesive = t.getUpperAdhesive();
this.upperAdhesiveWeight = t.getUpperAdhesiveWeight();
this.upperAuxWeight = t.getUpperAuxWeight();
this.upperAuxilliary = t.getUpperAuxilliary();
this.upperUnwind = t.getUpperUnwind();
this.upperUnwindWeight = t.getUpperUnwindWeight();
this.yarn = t.getYarn();
this.yarnWeight = t.getYarnWeight();
this.trialCtWtCheckList = t.getTrialCtWtCheckList();
}

... and getters and setters....

}

和 TrialCtWtCheck:

package com.lamtec.newtrial.service;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;


@Entity
@Table(name = "TrialCtWtCheck")
@XmlRootElement

public class TrialCtWtCheck implements Serializable {
private static final long serialVersionUID = 1L;
// @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
@Id
@Basic(optional = false)
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "COAT_WEIGHT")
private String coatWeight;
@Column(name = "FINISHED_MATERIAL_WT")
private String finishedMaterialWt;
@Column(name = "RAW_MATERIAL_TOT")
private String rawMaterialTot;
@ManyToOne
@JoinColumn(name="TRIAL_ID")
private Trial trialId;
public Trial getTrialId() {
return trialId;
}

public void setTrialId(Trial trialId) {
this.trialId = trialId;
}

public TrialCtWtCheck() {
super();
}

public TrialCtWtCheck(Long id, String coatWeight, String finishedMaterialWt, String rawMaterialTot, Trial trialId) {
this.id = id;
this.coatWeight = coatWeight;
this.finishedMaterialWt = finishedMaterialWt;
this.rawMaterialTot = rawMaterialTot;
}

public TrialCtWtCheck(Long id) {
this.id = id;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getCoatWeight() {
return coatWeight;
}

public void setCoatWeight(String coatWeight) {
this.coatWeight = coatWeight;
}

public String getFinishedMaterialWt() {
return finishedMaterialWt;
}

public void setFinishedMaterialWt(String finishedMaterialWt) {
this.finishedMaterialWt = finishedMaterialWt;
}

public String getRawMaterialTot() {
return rawMaterialTot;
}

public void setRawMaterialTot(String rawMaterialTot) {
this.rawMaterialTot = rawMaterialTot;
}


@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}

@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof TrialCtWtCheck)) {
return false;
}
TrialCtWtCheck other = (TrialCtWtCheck) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}

@Override
public String toString() {
return "com.lamtec.newtrials.entity.TrialCtWtCheck[ id=" + id + " ]";
}

}

存储库文件如下所示:

package com.lamtec.newtrial.service.repository;

import com.lamtec.newtrial.service.Trial;
import org.springframework.data.repository.CrudRepository;


public interface TrialRepository extends CrudRepository<Trial, Long> {

}

我的服务:

package com.lamtec.newtrial.service;

import com.lamtec.newtrial.service.repository.TrialRepository;
import java.util.List;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Repository
@Transactional(readOnly=true)
public class TrialServiceImpl implements TrialService {
@Inject private TrialRepository trialRepository;

@Override
public void addTrial(Trial trial) {
trialRepository.save(trial);
}

@Override
@Transactional(readOnly=true)
public List<Trial> listTrials() {
return (List<Trial>)trialRepository.findAll();
}
@Override
public Trial findTrial(Long Id) {
return trialRepository.findOne(Id);
}

@Override
@Transactional(readOnly=false)
public void updateTrial(Trial trial) {
trialRepository.save(trial);
}

}

war 文件在 GlassFish 3.1.2.2 服务器上成功构建并部署。我的开发环境是NetBeans 7.2。

当我针对服务运行客户端时,我得到以下堆栈跟踪:

org.springframework.remoting.RemoteAccessException: Could not deserialize result from HTTP invoker remote service [http://localhost:8080/NewTrialServer/new-trial.service]; nested exception is java.lang.ClassNotFoundException: org.springframework.transaction.CannotCreateTransactionException
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.convertHttpInvokerAccessException(HttpInvokerClientInterceptor.java:208)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:145)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy7.listTrials(Unknown Source)
at com.lamtec.newtrialclient.app.TrialsUIPresenter$1.call(TrialsUIPresenter.java:540)
at com.lamtec.newtrialclient.app.TrialsUIPresenter$1.call(TrialsUIPresenter.java:536)
at javafx.concurrent.Task$TaskCallable.call(Task.java:1229)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: org.springframework.transaction.CannotCreateTransactionException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:622)
at org.springframework.core.ConfigurableObjectInputStream.resolveClass(ConfigurableObjectInputStream.java:79)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1593)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1964)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1888)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1964)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1888)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor.doReadRemoteInvocationResult(AbstractHttpInvokerRequestExecutor.java:290)
at org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor.readRemoteInvocationResult(AbstractHttpInvokerRequestExecutor.java:241)
at org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor.doExecuteRequest(CommonsHttpInvokerRequestExecutor.java:143)
at org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor.executeRequest(AbstractHttpInvokerRequestExecutor.java:136)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest(HttpInvokerClientInterceptor.java:192)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest(HttpInvokerClientInterceptor.java:174)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:142)
... 9 more

我在堆栈跟踪中没有看到的一件事是,我在客户端和服务器之间的线路流量中看到的是:

    4317 [Thread-4] DEBUG httpclient.wire.content  - << "Exception Description: Cannot use an EntityTransaction while using JTA."

这是新的堆栈跟踪:

org.springframework.remoting.RemoteAccessException: Could not deserialize result from HTTP invoker remote service [http://localhost:8080/NewTrialServer/new-trial.service]; nested exception is java.lang.ClassNotFoundException: org.springframework.transaction.CannotCreateTransactionException
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.convertHttpInvokerAccessException(HttpInvokerClientInterceptor.java:208)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:145)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy7.listTrials(Unknown Source)
at com.lamtec.newtrialclient.app.TrialsUIPresenter$1.call(TrialsUIPresenter.java:540)
at com.lamtec.newtrialclient.app.TrialsUIPresenter$1.call(TrialsUIPresenter.java:536)
at javafx.concurrent.Task$TaskCallable.call(Task.java:1229)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: org.springframework.transaction.CannotCreateTransactionException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:622)
at org.springframework.core.ConfigurableObjectInputStream.resolveClass(ConfigurableObjectInputStream.java:79)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1593)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1964)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1888)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1964)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1888)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor.doReadRemoteInvocationResult(AbstractHttpInvokerRequestExecutor.java:290)
at org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor.readRemoteInvocationResult(AbstractHttpInvokerRequestExecutor.java:241)
at org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor.doExecuteRequest(CommonsHttpInvokerRequestExecutor.java:143)
at org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor.executeRequest(AbstractHttpInvokerRequestExecutor.java:136)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest(HttpInvokerClientInterceptor.java:192)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest(HttpInvokerClientInterceptor.java:174)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:142)
... 9 more

服务器和 IDE(我在其中启动客户端)之间的消息流量是:

"Could not open JPA EntityManager for transaction"

最佳答案

Caused by: java.lang.ClassNotFoundException: org.springframework.transaction.CannotCreateTransactionException

创建交易时似乎出现错误。这可能是由于 persistance.xml 或 glassfish 配置文件中的配置错误造成的。

<persistence-unit name="NewTrialsPU" transaction-type="JTA">

EntityManagerFactory 无法从 JNDI 找到事务。我没怎么用过glassfish。但这应该是找到实际问题的线索。应该有某种方法来验证 JNDI 资源是否在 glassfish 中创建并相应地使用它。

编辑

要快速解决问题,请考虑使用transaction-type="RESOURCE_LOCAL"并提供相关的数据库连接用户名密码 数据库信息应该会有所帮助。

关于java - Spring JPA TransactionManager 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11674722/

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