Peter Fuerholz (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5e468be...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiY2Q2YmVkNzU1...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-13866?atlOrigin=eyJpIjoiY2Q2Ym...
) HHH-13866 (
https://hibernate.atlassian.net/browse/HHH-13866?atlOrigin=eyJpIjoiY2Q2Ym...
) OneToOne-association produces error on 5.4.0+ when using PostgreSQL (
https://hibernate.atlassian.net/browse/HHH-13866?atlOrigin=eyJpIjoiY2Q2Ym...
)
Change By: Peter Fuerholz (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5e468be...
)
We have Spring Boot application using a OneToOne annotation and PostgreSQL.
Owning class:
```@Entity
{noformat} @Table(name = "PAYMENT")
public class PaymentDO {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "PAYMENT_ID", insertable = false, updatable = false, nullable =
false)
private Long paymentId;
@OneToOne(mappedBy = "payment", fetch = FetchType.LAZY, cascade =
CascadeType.ALL, orphanRemoval = true)
private PaymentBatchJobDO paymentBatchJob;
} {noformat}
```
Owned class:
```@Entity
{noformat} @Table(name = "PAYMENT_BATCH_JOB")
public class PaymentBatchJobDO {
@Id
@Column(name="PAYMENT_ID", updatable = false, nullable = false)
private Long paymentId;
@OneToOne
@PrimaryKeyJoinColumn(name = "PAYMENT_ID", referencedColumnName =
"PAYMENT_ID")
private PaymentDO payment;
} {noformat}
```
What I want to do is saving a PaymentDO and then add a PaymentBatchJobDO to it (using
Spring's JpaRepository). Strangely when trying to save the PaymentBatchJobDO this
fails.
The PaymentBatchJobDO is an optional child of PaymentDO. The relation is done using
'shared primary key'. This means PaymentBatchJobDO's paymentId-field becomes
same value as PaymentDO's paymentId-field.
Until Hibernate core 5.3.* that worked perfecty but with 5.4.* I get following error:
```2020-02-14 11:08:19.527 INFO 67291 --- [ main]
org.hibernate.dialect.Dialect : HHH000400: Using dialect:
org.hibernate.dialect.PostgreSQL95Dialect
{noformat} 2020-02-14 11:08:20.631 INFO 67291 --- — [ main]
o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation:
[org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-02-14 11:08:20.636 INFO 67291 --- — [ main]
j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for
persistence unit 'default'
Payment onlyPaymentDO{paymentId=1945, paymentBatchJob=null, amountTotal=12.00}
PaymentPaymentDO{paymentId=1945, paymentBatchJob=null, amountTotal=12.00}
2020-02-14 11:08:21.108 ERROR 67291 --- — [ 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)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.internal.AbstractSharedSessionContract.generateEntityKey(AbstractSharedSessionContract.java:523)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.type.OneToOneType.isNull(OneToOneType.java:105)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.type.EntityType.resolve(EntityType.java:462)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.type.EntityType.resolve(EntityType.java:457)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.type.EntityType.replace(EntityType.java:358)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.type.AbstractType.replace(AbstractType.java:164)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.type.TypeHelper.replace(TypeHelper.java:204)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.event.internal.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:488)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.event.internal.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:241)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:318)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:172)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:70)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:108)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:776)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:763)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
~[na:na]
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
~[na:na]
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at
org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:314)
~[spring-orm-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at com.sun.proxy.$Proxy73.merge(Unknown Source) ~[na:na]
at
org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:557)
~[spring-data-jpa-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
~[na:na]
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
~[na:na]
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at
org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:371)
~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at
org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:204)
~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at
org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:657)
~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:621)
~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at
org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:605)
~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80)
~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:353)
~[spring-tx-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:99)
~[spring-tx-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
~[spring-tx-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:178)
~[spring-data-jpa-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at com.sun.proxy.$Proxy86.save(Unknown Source) ~[na:na]
at
com.swisscom.billing.testhibernate.PaymentsTxService.addPaymentBatchJob(PaymentsTxService.java:53)
~[main/:na]
at
com.swisscom.billing.testhibernate.PaymentsTxService$$FastClassBySpringCGLIB$$4919717e.invoke(<generated>)
~[main/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
~[spring-core-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:769)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:353)
~[spring-tx-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:99)
~[spring-tx-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
com.swisscom.billing.testhibernate.PaymentsTxService$$EnhancerBySpringCGLIB$$604ba717.addPaymentBatchJob(<generated>)
~[main/:na]
at com.swisscom.billing.testhibernate.StartupBean.onApplicationEvent(StartupBean.java:35)
~[main/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
~[na:na]
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
~[na:na]
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na] {noformat}
```
If I use a H2 database the error does not occur.
Configuration:
```spring.jpa.hibernate.use-new-id-generator-mappings=true
{noformat}
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL95Dialect {noformat}
```
There are different ways to implement a OneToOne relationship. If I change to the
(probably more typical):
Owned class:
``` @OneToOne
{noformat} @MapsId
private PaymentDO payment;
``` {noformat}
I get following error:
```2020-02-14 11:25:41.048 WARN 74847 --- [ main]
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 42703
{noformat} 2020-02-14 11:25:41.048 ERROR 74847 --- — [ main]
o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: column paymentbat0_.payment_payment_id
does not exist
Position: 8
2020-02-14 11:25:41.054 INFO 74847 --- — [ main]
o.h.e.internal.DefaultLoadEventListener : HHH000327: Error performing load command :
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at
org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:103)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:67)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.loader.Loader.getResultSet(Loader.java:2287)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2045)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2007)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.loader.Loader.doQuery(Loader.java:953)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:324)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.loader.Loader.loadEntity(Loader.java:2401)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:64)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.loader.entity.EntityLoader.loadByUniqueKey(EntityLoader.java:144)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:2384)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:745)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.type.EntityType.resolve(EntityType.java:467)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:226)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:160)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.performTwoPhaseLoad(AbstractRowReader.java:255)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.finishUp(AbstractRowReader.java:215)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:141)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:105)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:197)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4350)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:570)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:538)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:208)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:333)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:108)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:74)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:118)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.internal.SessionImpl.fireLoadNoChecks(SessionImpl.java:1182)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1171)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:198)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.doLoad(SessionImpl.java:2809)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.lambda$load$1(SessionImpl.java:2790)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at
org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.perform(SessionImpl.java:2746)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2790)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3340)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3312)
~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
~[na:na]
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
~[na:na]
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at
org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:314)
~[spring-orm-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at com.sun.proxy.$Proxy74.find(Unknown Source) ~[na:na]
at
org.springframework.data.jpa.repository.support.SimpleJpaRepository.findById(SimpleJpaRepository.java:281)
~[spring-data-jpa-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
~[na:na]
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
~[na:na]
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at
org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:371)
~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at
org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:204)
~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at
org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:657)
~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:621)
~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at
org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:605)
~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80)
~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:353)
~[spring-tx-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:99)
~[spring-tx-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
~[spring-tx-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:178)
~[spring-data-jpa-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at com.sun.proxy.$Proxy83.findById(Unknown Source) ~[na:na]
at com.swisscom.billing.testhibernate.StartupBean.onApplicationEvent(StartupBean.java:28)
~[main/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
~[na:na]
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
~[na:na]
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na] {noformat}
```
--> paymentbat0_.payment_payment_id does not exist \ !
If I set ` {{ hibernate.id.disable_delayed_identity_inserts=true ` }} the error does
not change in any way.
I tried using hibernate-core in version 5.4.0.CR1 & 2 as well but error occurs there
identically. Furthermore I noticed that when I update to hibernate-core 5.4.0 I get newer
versions of hibernate-commons-annotations, javaassist an org.jboss:jandex. If I these back
to the state used for hibernate-core 5.3.* error is still the same. Thus the error
originates definitely in the hibernate-core 5.4.* version.
Since it is a Spring Application I use SimpleJpaRepository's save() method. As I have
seen now this method calls EntityManager.merge() (do notice: not persist()) although the
object to save is new. When using hibernate-core on versions 5.3.* this properly saved the
object.
The fact that EntityManager.merge() is called is, that the ID-field is already filled out.
This is a result of the 'shared primary key' used for the one-to-one relation.
My question is thus: Have the rules using EntityManager.merge changed? Was it just luck
the old code worked or should EntityManager.merge work lenient enough to check that the
object is not yet saved and persist it properly? (In Hibernate's Session.merge-Javadoc
I read: "If the given instance is unsaved, save a copy of and return it as a newly
persistent instance.")
As a workaround I called EntityManager.persist() instead of SimpleJpaRepository's
save() which helped. Nevertheless it is bad practice to mix both APIs.
(
https://hibernate.atlassian.net/browse/HHH-13866#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-13866#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100121- sha1:6148daa )