I'm trying to upgrade a project to spring boot 2.2+ (2.2.8.RELEASE, but happens on higher versions also )but for some reason, when i run the tests, i get:
2020-07-04 10:34:54.614 ERROR 92979 --- [ main] org.hibernate.AssertionFailure
: HHH000099: an assertion failure occurred (this may indicate a bug in Hibernate, but is more
likely due to unsafe use of the session): org.hibernate.AssertionFailure: null identifier
org.hibernate.AssertionFailure: null identifier
at org.hibernate.engine.spi.EntityKey.<init>(EntityKey.java:51)
at org.hibernate.internal.AbstractSharedSessionContract.generateEntityKey(AbstractSharedSessionContract.java:527)
at org.hibernate.type.OneToOneType.isNull(OneToOneType.java:105)
at org.hibernate.type.EntityType.resolve(EntityType.java:462)
...
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy172.save(Unknown Source)
the code that invokes it (didn't change since the upgrade):
private fun persist(vararg podcasts: Podcast) {
for (podcast in podcasts) {
podcastRepository.save(podcast)
podcastMetadataRepository.save(podcast.importMetadata)
}
}
...
interface PodcastRepository : JpaRepository<Podcast, String> {...
here's the entity:
@Entity
@EntityListeners(AuditingEntityListener::class)
data class Podcast(
@Id
override val id: String
...
the id is created in code
It seems like a bug in hibernate/spring boot 2.2
The error comes from SessionImpl.merge(object)
, according to my investigation, at some point, the entity is checked against the db a second time, where it sees a null id, although the first time it is there.
Comment From: wilkinsona
Thanks for the report.
Spring Boot itself isn’t involved at that point. I suspect the problem is either in Spring Data JPA or in Hibernate. You haven’t said from which version you are upgrading, but I suspect both projects will have newer versions in Spring Boot 2.2.8 than you were using before.
I would recommend comparing the versions of Spring Data JPA and Hibernate that are being used when the problem occurs and when it does not. Then, by overriding the version of either project you should hopefully be able to determine the version that causes the change in behaviour. At that point, if you believe the behaviour change is a bug, opening an issue against the relevant project would be appropriate.
If the above doesn’t help you to identify the cause and you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue. We can then re-open the issue and take another look.