gpt4 book ai didi

java - Hibernate JPA 和 Spring javax.persistence.TransactionRequiredException : no transaction is in progress (2)

转载 作者:行者123 更新时间:2023-12-01 23:09:36 30 4
gpt4 key购买 nike

同样的问题,但相关帖子中给出的其他答案对我没有帮助。

Maven 格式的源代码位于:

https://github.com/jjYBdx4IL/my.bugs.smtpserver

git clone git@github.com:jjYBdx4IL/my.bugs.smtpserver.git

“mvn test”期间抛出异常:

javax.persistence.TransactionRequiredException: no transaction is in progress
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.checkTransactionNeeded(AbstractEntityManagerImpl.java:1171)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1332)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:334)
at com.sun.proxy.$Proxy30.flush(Unknown Source)
at my.bugs.smtpserver.MessageHookImpl.storeEMail(MessageHookImpl.java:46)
at my.bugs.smtpserver.MessageHookImpl.onMessage(MessageHookImpl.java:30)
at org.apache.james.protocols.smtp.core.DataLineMessageHookHandler.processExtensions(DataLineMessageHookHandler.java:128)
at org.apache.james.protocols.smtp.core.DataLineMessageHookHandler.onLine(DataLineMessageHookHandler.java:76)
at org.apache.james.protocols.smtp.core.DataCmdHandler$DataLineFilterWrapper.onLine(DataCmdHandler.java:84)
at org.apache.james.protocols.smtp.core.DataCmdHandler$DataLineFilterWrapper.onLine(DataCmdHandler.java:67)
at org.apache.james.protocols.smtp.core.SeparatingDataLineFilter.onBodyLine(SeparatingDataLineFilter.java:111)
at org.apache.james.protocols.smtp.core.SeparatingDataLineFilter.onLine(SeparatingDataLineFilter.java:69)
at org.apache.james.protocols.smtp.core.DataCmdHandler$DataLineFilterWrapper.onLine(DataCmdHandler.java:84)
at org.apache.james.protocols.smtp.core.DataCmdHandler$DataLineFilterWrapper.onLine(DataCmdHandler.java:67)
at org.apache.james.protocols.smtp.core.esmtp.MailSizeEsmtpExtension.onLine(MailSizeEsmtpExtension.java:151)
at org.apache.james.protocols.smtp.core.DataCmdHandler$DataLineFilterWrapper.onLine(DataCmdHandler.java:84)
at org.apache.james.protocols.smtp.core.DataCmdHandler$DataLineFilterWrapper.onLine(DataCmdHandler.java:67)
at org.apache.james.protocols.netty.LineHandlerUpstreamHandler.messageReceived(LineHandlerUpstreamHandler.java:50)
at org.jboss.netty.handler.timeout.IdleStateHandler.messageReceived(IdleStateHandler.java:270)
at org.jboss.netty.handler.stream.ChunkedWriteHandler.handleUpstream(ChunkedWriteHandler.java:143)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:327)
at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:305)
at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:207)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:343)
at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:274)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:194)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)

知道我做错了什么吗?

最佳答案

您的事务方法storeEMail 正在由onMessage 直接调用。事务行为由包装 storeEMail 的 AOP 代理实现。由于您直接调用 storeEMail,因此不会调用 AOP 代理,并且您没有事务。 storeEMail 需要在注入(inject)的 bean 引用上调用。您可能需要重新考虑您的设计。

关于java - Hibernate JPA 和 Spring javax.persistence.TransactionRequiredException : no transaction is in progress (2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22227412/

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