[英]Does CrudRepository.save return null for spring data 1.13.18.RELEASE
I understand that for the current version( 2.xx
) of spring-data-commons
it is guaranteed that the return value of CrudRepository.save()
will never be null.我知道对于
spring-data-commons
的当前版本( 2.xx
),可以保证CrudRepository.save()
的返回值永远不会是 null。 However, what about the older versions, specifically 1.13.18.RELEASE ?但是,旧版本,特别是1.13.18.RELEASE呢?
If the older version does guarantee return of non-null values then it renders the following piece of code useless, right?如果旧版本确实保证返回非空值,那么它会使下面的代码无用,对吧?
Entity savedEntity = someRepository.save(entity);
if (savedEntity == null) {
// throw some checked exception stating that the save failed..
}
And if the older version doesn't guarantee return of a non-null value, then what scenario would lead to the return of a null value?如果旧版本不保证返回非空值,那么什么情况会导致返回 null 值?
Update : Since my question is pertaining to the implementation of CrudRepository
, it is important to point out that I am using 1.11.18.RELEASE
of spring-data-jpa
.更新:由于我的问题与
CrudRepository
的实施有关,重要的是要指出我正在使用1.11.18.RELEASE
的spring-data-jpa
。 I want to know about the behaviour of save function for this version.我想了解此版本保存function 的行为。
According to implementation , it will always return a value or throw an exception根据实现,它总是会返回一个值或抛出一个异常。
Update the implementation is for 1.11.18.RELEASE
.更新实现是针对
1.11.18.RELEASE
的。 From GitHub repository来自 GitHub 存储库
@Transactional
public <S extends T> S save(S entity) {
if (this.entityInformation.isNew(entity)) {
this.em.persist(entity);
return entity;
} else {
return this.em.merge(entity);
}
}
same issue here.同样的问题。 Even though it should never return null, in my project I get a null value (silent failure) when I update an existing entity.
即使它永远不应该返回 null,但在我的项目中,当我更新现有实体时,我会得到一个 null 值(静默失败)。 If I create a new entity it works.
如果我创建一个新实体,它就可以工作。 I tried also implementing the Persistable interface, but still the same issue.
我也尝试实现 Persistable 接口,但仍然是同样的问题。 I am using Spring Data + R2DBC + Java 15.
我正在使用 Spring 数据 + R2DBC + Java 15。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.