- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试使用 Spring Data Repository 保存数据时,收到可嵌入实体的 javax.persistence.EntityNotFoundException。似乎 select 语句没有找到我的嵌入实体 CommunicationPreference
的数据。我该如何修复这个错误?
堆栈跟踪:
org.springframework.orm.jpa.JpaObjectRetrievalFailureException: Unable to find com.talentreef.notification.recipient.persistent.models.CommunicationPreference with id 61390ce8-719c-44e4-9cab-57070d728456; nested exception is javax.persistence.EntityNotFoundException: Unable to find com.talentreef.notification.recipient.persistent.models.CommunicationPreference with id 61390ce8-719c-44e4-9cab-57070d728456
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:378)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:255)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:527)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:144)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$ExposeRepositoryInvocationInterceptor.invoke(CrudMethodMetadataPostProcessor.java:364)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy106.save(Unknown Source)
at com.talentreef.notification.recipient.persistent.services.RecipientPersistService.upsert(RecipientPersistService.java:33)
at com.talentreef.notification.recipient.persistent.services.RecipientPersistentServiceTest.shouldSaveRecipient(RecipientPersistentServiceTest.java:127)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: javax.persistence.EntityNotFoundException: Unable to find com.talentreef.notification.recipient.persistent.models.CommunicationPreference with id 61390ce8-719c-44e4-9cab-57070d728456
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$JpaEntityNotFoundDelegate.handleEntityNotFound(EntityManagerFactoryBuilderImpl.java:162)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:234)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:350)
at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:127)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:93)
at org.hibernate.internal.SessionImpl.fireLoadNoChecks(SessionImpl.java:1288)
at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1160)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:682)
at org.hibernate.type.EntityType.resolve(EntityType.java:464)
at org.hibernate.type.ManyToOneType.resolve(ManyToOneType.java:239)
at org.hibernate.type.EntityType.resolve(EntityType.java:457)
at org.hibernate.type.EntityType.replace(EntityType.java:358)
at org.hibernate.type.AbstractType.replace(AbstractType.java:164)
at org.hibernate.type.TypeHelper.replace(TypeHelper.java:203)
at org.hibernate.event.internal.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:502)
at org.hibernate.event.internal.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:257)
at org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:334)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:188)
at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:927)
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:897)
at org.hibernate.engine.spi.CascadingActions$6.cascade(CascadingActions.java:261)
at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:490)
at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:415)
at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:216)
at org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:523)
at org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:455)
at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:418)
at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:216)
at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:149)
at org.hibernate.event.internal.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:459)
at org.hibernate.event.internal.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:263)
at org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:334)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:188)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:72)
at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:905)
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:891)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:309)
at com.sun.proxy.$Proxy104.merge(Unknown Source)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:538)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:359)
at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:644)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:608)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:295)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
... 43 more
hibernate 查询:
Hibernate:
select
recipient0_.recipient_id as recipien1_1_1_,
recipient0_.alias as alias2_1_1_,
recipient0_.email as email3_1_1_,
recipient0_.firstname as firstnam4_1_1_,
recipient0_.lastname as lastname5_1_1_,
recipient0_.mobile as mobile6_1_1_,
audiences1_.recipient_recipient_id as recipien1_3_3_,
audience2_.audience_id as audience2_3_3_,
audience2_.audience_id as audience1_2_0_,
audience2_.alias as alias2_2_0_,
audience2_.client_id as client_i3_2_0_,
audience2_.recipient_id as recipien4_2_0_,
audience2_.type as type5_2_0_
from
notification.recipient recipient0_
left outer join
notification.recipient_audiences audiences1_
on recipient0_.recipient_id=audiences1_.recipient_recipient_id
left outer join
notification.recipient_audience audience2_
on audiences1_.audiences_audience_id=audience2_.audience_id
where
recipient0_.recipient_id=?
Hibernate:
select
audience0_.audience_id as audience1_2_1_,
audience0_.alias as alias2_2_1_,
audience0_.client_id as client_i3_2_1_,
audience0_.recipient_id as recipien4_2_1_,
audience0_.type as type5_2_1_,
followers1_.audience_id as audience2_4_3_,
followers1_.follower_id as follower1_4_3_,
followers1_.follower_id as follower1_4_0_,
followers1_.audience_id as audience2_4_0_,
followers1_.client_id as client_i3_4_0_,
followers1_.follower_recipient as follower4_4_0_,
followers1_.recipient_id as recipien5_4_0_
from
notification.recipient_audience audience0_
left outer join
notification.recipient_follower followers1_
on audience0_.audience_id=followers1_.audience_id
where
audience0_.audience_id=?
Hibernate:
select
follower0_.follower_id as follower1_4_0_,
follower0_.audience_id as audience2_4_0_,
follower0_.client_id as client_i3_4_0_,
follower0_.follower_recipient as follower4_4_0_,
follower0_.recipient_id as recipien5_4_0_
from
notification.recipient_follower follower0_
where
follower0_.follower_id=?
Hibernate:
select
recipientp0_.preference_id as preferen1_7_0_,
recipientp0_.client_id as client_i2_7_0_,
recipientp0_.list_id as list_id6_7_0_,
recipientp0_.last_modified as last_mod3_7_0_,
recipientp0_.recipient_id as recipien4_7_0_,
recipientp0_.source_type as source_t5_7_0_
from
notification.recipient_preference recipientp0_
where
recipientp0_.preference_id=?
Hibernate:
select
communicat0_.list_id as list_id1_0_0_,
communicat0_.email as email2_0_0_,
communicat0_.sms as sms3_0_0_,
communicat0_.stream as stream4_0_0_
from
notification.preference_list communicat0_
where
communicat0_.list_id=?
数据模型:
@Builder
@Getter
@Entity
@Embeddable
@Table(name = RecipientPreferenceTable.NAME, schema = Notification.SCHEMA_NAME)
public class RecipientPreference {
@Id
@Column(name = RecipientPreferenceTable.COLUMN_PREFERENCE_ID, unique = true, length = 16)
private UUID id;
@Column(name = RecipientPreferenceTable.COLUMN_RECIPIENT_ID, nullable = false, length = 16)
private UUID recipientId;
@Column(name = RecipientPreferenceTable.COLUMN_CLIENT_ID, nullable = false)
private String clientId;
@OneToOne
@AttributeOverride(name = "id", column = @Column(name = CommunicationPreferenceTable.COLUMN_LIST_ID, nullable = false))
@JoinColumn(name = CommunicationPreferenceTable.COLUMN_LIST_ID)
private CommunicationPreference communicationPreference;
@Enumerated(EnumType.STRING)
@Column(name = RecipientPreferenceTable.COLUMN_SOURCE_TYPE)
private SourceType sourceType;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = RecipientPreferenceTable.COLUMN_LAST_MODIFIED)
private Date lastModified;
protected RecipientPreference() {}
public RecipientPreference(UUID id,
UUID recipientId,
String clientId,
CommunicationPreference communicationPreference,
SourceType sourceType,
Date lastModified) {
this.id = id;
this.recipientId = recipientId;
this.clientId = clientId;
this.communicationPreference = communicationPreference;
this.sourceType = sourceType;
this.lastModified = lastModified;
}
}
@Builder
@Getter
@Entity
@Embeddable
@Table(name = CommunicationPreferenceTable.NAME, schema = Notification.SCHEMA_NAME)
public class CommunicationPreference {
@Id
@Column(name = CommunicationPreferenceTable.COLUMN_LIST_ID, length = 16)
private UUID id;
private boolean sms;
private boolean email;
private boolean stream;
protected CommunicationPreference(){}
public CommunicationPreference(UUID id, boolean sms, boolean email, boolean stream) {
this.id = id;
this.sms = sms;
this.email = email;
this.stream = stream;
}
}
最佳答案
数据库中不存在 ID 为 61390ce8-719c-44e4-9cab-57070d728456 的 CommunicationPreference
。
它应该在测试之前创建,或者应修改 RecipientPreference
与 CommunicationPreference
的 OneToOne 关系以允许自动创建:
public class RecipientPreference {
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
@AttributeOverride(name = "id", column = @Column(name = CommunicationPreferenceTable.COLUMN_LIST_ID, nullable = false))
@JoinColumn(name = CommunicationPreferenceTable.COLUMN_LIST_ID)
private CommunicationPreference communicationPreference;
}
关于java - Spring JPA hibernate H2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58495385/
我有以下情况要解决,但无法正常工作(尝试了Hibernate和EclipseLink): Table_1: Column_A is Primary Key ... some other
我是 JPA 的新手,但必须在该技术中实现我的项目 我想做的是通过 CriteriaQuery 构建一些数据库查询,但不知道如何将参数列表传递给下面的代码: CriteriaBuilder qb =
我是 JPA 新手,注意到可以通过使用 @Version 注释实体中的字段来使用乐观锁定。我只是好奇,如果之前不存在,持久性提供程序是否会创建一个隐式版本字段。例如网站objectdb状态: "Whe
我有一个 JPA 查询 @Query(value = "SELECT SUM(total_price) FROM ... WHERE ...", nativeQuery = true) 当有匹配的记录
JPA 是否会尝试在已经持久(和非分离)的实体上级联持久化? 为了清楚起见,这是我的情况:我想保留一个新用户: public void addUser(){ //User is an enti
显然,OpenJPA。我也看到提到过 EclipseLink 和 Hibernate,但是在功能上有显着差异吗? 最佳答案 大多数差异来自提供者对 OSGi 的感知程度。例如,您可能需要自己将 Hib
我想将 JPA 用于 micronaut。为此,我使用 io.micronaut.data:micronaut-data-hibernate-jpa:1.0.0.M1 库。每当我运行应用程序并点击端点
我正准备为我的应用实现后端,现在我正在投影数据层。我期待着 Spring 。 最佳答案 Spring Data JPA 不是 JPA 实现。它提供了将数据访问层构建到底层 JPA 顶部的方法。您是否应
假设我有一个表 Item,其中包含一个名为 user_id 的列和一个表 User 以及另一个名为 Superuser 的列: CREATE TABLE Item(id int, user_id in
JPA 2.1 规范说: The entity class must not be final. No methods or persistent instance variables of the
我正在从事一个具有一些不寻常实体关系的项目,我在使用 JPA 时遇到了问题。有两个相关对象;用户,让我们称另一个 X。用户与 X 具有一对多和两个一对一的关系。它基本上看起来像这样 [用户实体] @O
我说的是 JavaEE 中的 JPA。在我读过的一本书中谈到: EntityManager em; em.find(Employee.class, id); “这是实体管理器在数据库中查找实例所需的所
我有 JPA 支持的 Vaadin 应用程序。此应用程序中的组件绑定(bind)到 bean 属性(通过独立的 EL 实现)。一些组件绑定(bind)到外部对象(或其字段),由@OneToOne、@O
是否可以使表中的外键唯一?假设我有实体 A 和 B。 答: @Entity class A extends Serializable { @Id private long id; @OneToOne
我在使用 JPA 时遇到了一点问题。考虑这种情况: 表 A (id_a) | 表 B (id_b, id_a) 我需要的是这样的查询: Select a.*, c.quantity from A as
我有一个由 JPA 管理的实体类,我有一个实体需要在其属性中记录更改。 JPA 是否提供任何方法来处理这种需求? 最佳答案 如果您使用 Hibernate 作为 JPA 提供程序,请查看 Hibern
我想实现以下架构: Table A: a_id (other columns) Table B: b_id (other columns) Table C: c_id (other columns)
我有一个愚蠢的问题。如果能做到的话那就太好了,但我并没有屏住呼吸。 我需要链接到我的 JPA 实体的表中的单个列作为所述 JPA 实体中的集合。有什么方法可以让我单独取回与该实体相关的列,而不必取回整
我有一个 Open JPA 实体,它成功连接了多对多关系。现在我成功地获取了整个表,但我实际上只想要该表中的 ID。我计划稍后调用数据库来重建我需要的实体(根据我的程序流程)。我只需要 ID(或该表中
这是我的一个实体的复合主键。 public class GroupMembershipPK implements Serializable{ private static final long
我是一名优秀的程序员,十分优秀!