首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Insert语句中结果的获取方法

Insert语句中结果的获取方法
EN

Stack Overflow用户
提问于 2022-06-30 22:43:23
回答 1查看 94关注 0票数 0

我试图理解"get“方法(findXByYAndZAnd.)在存储库中,使用ORA-00001“违反了唯一约束()”,(org.springframework.data.repository.CrudRepository)就会失败。

显然,insert是从另一个(前一个)语句中生成的,但是,我不明白Spring和CrudMethodMetadataPostProcessor的角色是什么,为什么事务会在其中提交。我们确实有

代码语言:javascript
复制
dbConfig:
... 
    hikari:
      auto-commit: true 

代码语言:javascript
复制
spring:
  application:
    name: xxx
  cache:
    type: caffeine
  jpa:
    database: oracle
    properties:
      hibernate:
        jdbc: 
          batch_size: 200
#          order_inserts: true
#          order_updates: true
#          show_sql: true
        use_sql_comments: false
        format_sql: false

但还是..。它要么立即完成交易,要么在最后完成,不是吗?

代码语言:javascript
复制
ERROR 42664956 --- [task-10] c.e.my-app.service.error.DbLoggerService    : Error saving messages : org.hibernate.exception.ConstraintViolationException: could not execute batch; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute batch
RootCause: 
ORA-00001: unique constraint (SIDE.PK_RMESG) violated
Stack Trace: 

org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.ConstraintViolationException: could not execute batch; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute batch
    at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:408) ~[spring-orm-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
    at org.springframework.orm.jpa.DefaultJpaDialect.translateExceptionIfPossible(DefaultJpaDialect.java:128) ~[spring-orm-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:528) ~[spring-orm-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61) ~[spring-tx-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
    at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242) ~[spring-tx-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:154) ~[spring-tx-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:149) ~[spring-data-jpa-2.3.4.RELEASE.jar!/:2.3.4.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95) ~[spring-aop-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
    at com.sun.proxy.$Proxy162.getInstanceByxAndYAndZ(Unknown Source) ~[na:na]
    at com.my-org.my-app.my-component.service.impl.PartServiceImpl.process(PartServiceImpl.java:287) ~[loader-1.0.0-SNAPSHOT.jar!/:1.0.0-SNAPSHOT]

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-07 07:22:39

我没有看到任何交易被提交的迹象。由于您不共享任何代码,所以我们只能猜测,但可能会发生以下情况:

您对一些托管实体做了一些更改。这可能是通过使用实体调用save,或者修改加载在同一事务中的实体。

这些更改不会立即刷新到数据库,但会尽可能延迟。

然后执行或触发某种查询。在默认情况下,JPA的配置会触发更改的刷新,从而触发异常。

CrudMethodMetadataPostProcessor.CrudMethodMetadataPopulatingMethodInterceptor在这里似乎不相关。它只是收集有关被调用的方法的一些信息,然后继续到被调用的方法的实际实现(或下一个方面)。您可以在这里看到invoke方法:https://github.com/spring-projects/spring-data-jpa/blob/b57eb85a230d3a05e45276052ef62b1249e5a0e6/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/CrudMethodMetadataPostProcessor.java#L128

至于AOP,它只是一种机制,用于获取诸如CrudMethodMetadataPostProcessor或事务管理,甚至是要执行存储库方法本身的实现。除了对Spring数据本身至关重要(记住,存储库只是没有正常实现的接口)之外,它并没有真正影响上面描述的JPA行为。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72822731

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档