在弹簧存储库中获取方法在插入语句中结果
我试图了解在存储库(org.springframework.data.repository.crudrepository)上的“获取”方法(findxbyyandzand ...)如何使用ORA-00001“唯一约束()违反”。
显然,插入物是从另一个(以前的)语句中生成的,但是,我不明白Spring AOP和CrudmethodmetadatapostProcessor的作用是什么,为什么交易是在其中间进行的。我们确实有
dbConfig:
...
hikari:
auto-commit: true
,但
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
仍然...它应该立即进行交易,或者最后,不是吗?
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]
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有看到交易进行的任何迹象。由于您不共享任何代码,我们只能猜测,但是可能发生的事情是:
您对某些托管实体进行了一些更改。
这可能是通过使用实体调用
保存
,或者通过修改您在同一事务中加载的实体。这些更改不会立即冲入数据库,但会尽可能长时间延迟。
然后,您执行或触发某种查询。
默认情况下,JPA的配置会触发更改的冲洗,因此触发了例外。
crudmethodmetadatapostprocessor.crudmethodmetadatapulatingmethodinterceptor
在这里似乎并不重要。它只是收集有关所调用方法的一些信息,然后继续进行所调用方法的实际实现(或下一个方面)。您可以在此处查看Invoke
方法:https://github.com/spring-projects/spring-data-jpa/blob/b57eb85a230d3a05e45276052ef62b1249e5a0e6 /spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/support/crudmethodmetadatapostprocessor.java#l128为了获得类似的机械师,它只是一种机械师crudmethodmetadatapostprocessor 或事务管理,甚至是要执行的存储库方法的实现。
除了对弹簧数据本身至关重要(请记住,存储库只是没有正常实现的接口),它并没有真正影响上述JPA行为。
I don't see any sign that a transaction was committed. Since you don't share any code we can only guess but what is probably going on is the following:
You made some changes to some managed entities.
This might be by calling
save
with an entity, or by modifying an entity that you loaded in the same transaction.These changes don't get flushed to the database immediately, but are delayed as long as possible.
You then perform or trigger some kind of query.
This by default configuration of JPA triggers a flush of the changes and therefore the exception.
CrudMethodMetadataPostProcessor.CrudMethodMetadataPopulatingMethodInterceptor
doesn't seem to be relevant here. It just gathers some information about the method invoked and then proceeds to the actual implementation (or next aspect) of the method invoked. You can see theinvoke
method here: https://github.com/spring-projects/spring-data-jpa/blob/b57eb85a230d3a05e45276052ef62b1249e5a0e6/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/CrudMethodMetadataPostProcessor.java#L128As for AOP it is just a mechanic used for get things like
CrudMethodMetadataPostProcessor
or transaction management and even the implementation of repository methods themselves to be executed.Apart from being crucial for Spring Data itself (remember repositories are just interfaces without normal implementation) it is not really affecting the JPA behaviour described above.