【发布时间】:2019-05-20 23:04:48
【问题描述】:
我面临着一个我什至找不到调试方法的情况。
我有以下spring-data 存储库:
IntegrationLogRepository
public interface IntegrationLogRepository extends PagingAndSortingRepository<IntegrationLog, Long> {
}
FooRepository
public interface FooRepository extends PagingAndSortingRepository<Foo, Long> {
}
在我的业务逻辑上,我有如下内容:
IntegrationLog log = new IntegrationLog();
log.setTimestamp(new Date());
try {
Foo foo = new Foo();
// Build the Foo object...
fooRepository.save(foo);
log.setStatus("OK");
} catch (Exception e) {
log.setStatus("NOK");
} finally {
integrationLogRepository.save(log);
}
当集成运行良好时,log 会以OK 状态保存。一切顺利。但是当我遇到异常时,出于某种原因integrationLogRepository.save(log) 不会什么都不做。我什么都没有:没有抛出异常,我看不到任何休眠查询正在我的 WebLogic 控制台上执行。日志没有持久化...
关于为什么会发生这种情况的任何想法?
以下是我的依赖项:
compile 'org.springframework.boot:spring-boot-starter-data-rest'
compile 'org.springframework.boot:spring-boot-starter-security'
compile "org.springframework.boot:spring-boot-starter-web-services"
runtime 'org.springframework.boot:spring-boot-devtools'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile "org.springframework.boot:spring-boot-starter-websocket"
compile 'javax.servlet:javax.servlet-api:3.1.0'
compile 'org.hibernate:hibernate-core:5.1.16.Final'
compile 'org.hibernate:hibernate-validator:5.2.3.Final'
compile 'org.hibernate:hibernate-entitymanager:5.1.0.Final'
在 Spring Boot 1.5.15.RELEASE、Java 1.7 和 WebLogic 12.1.3 上运行。
谢谢!
【问题讨论】:
-
是否假设整个方法中有@Transactional?
-
你的意思是我的业务逻辑的方法?没有@Transactional ...应该有吗?你能解释一下为什么吗?
-
我只是尝试用 @Transactional 注释它并得到相同的结果:没有任何反应:/
-
好吧,你可以添加@Transactional(noRollbackFor = {Exception.class}) 来消除回滚作为罪魁祸首
-
好的!我“解决了”它。用
@Transactional(propagation = Propagation.NOT_SUPPORTED)注释该方法似乎可以使其工作。现在,如果有人可以向我解释为什么,如果这是正确的事情,我很乐意给予奖励积分 n_n'
标签: java hibernate spring-boot spring-data