我有3个表:数据库,表,字段。它们与一对多的关系相关联。 数据库一对多表一对多字段。 但是当我从jpa存储库调用save方法时,我得到了下一个异常。我也在检查stackowerflow的答案。在多对一关系上添加注释@NotFound(action = NotFoundAction.IGNORE)并没有帮助。
引起:javax.persistence.EntityNotFoundException:无法在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ JpaEntityNotFoundDelegate.handleEntityNotFound(EntityManagerFactoryBuilderImpl)中找到id为79fa34b6-b2e7-4c13-a4c8-e8f216a4b4c7的com.domain.Table。的java:158)在org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)在org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278)在org.hibernate.event.internal .DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121)在org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89)在org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1239)在有机hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1122)在org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:646)在org.hibernate.type.EntityType.resolve(EntityType.java:431)在组织.hibernate.type.EntityType位于org.hibernate.type的org.hibernate.type.CollectionType.replace(CollectionType.java:688)org.hibernate.type.CollectionType.replaceElements(CollectionType.java:543)的.replace(EntityType.java:330)。 AbstractType.replace(AbstractType.java:144)在org.hibernate.type.TypeHelper.replaceAssociations(TypeHelper.java:264)在org.hibernate.event.internal.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:420)在org.hibernate作为.event.internal.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:240)atg.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:301)org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java) :170)在org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:69)在org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:883)在org.hibernate.internal.SessionImpl.merge( SessionImpl.java:869)在sun.reflect。 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)中的NativeMethodAccessorImpl.invoke0(Native Method)位于sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)的java.lang.reflect.Method.invoke(方法。 Java的:498)在org.springframework.orm.jpa.SharedEntityManagerCreator $ SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:298)在com.sun.proxy $ Proxy150.merge(来源不明)在org.springframework.data.jpa.repository。 .support.SimpleJpaRepository.save(SimpleJpaRepository.java:511)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl的.java:43)在java.lang.reflect.Method.invoke(Method.java:498)在org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.ja va:504)org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:489)at org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport。 java:461)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)atg.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:56)at org.springframework.aop.framework .ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)org.springframework.transaction.interceptor.TransactionInterceptor $ 1.proceedWithInvocation(TransactionInterceptor.java:99)at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)在org.springframework.transaction.interceptor.TransactionInterceptor.invoke(Trans actionInterceptor.java:96)在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)在org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)... 141个共同框架省略
数据库类:
@Entity
@Table(name = "data_base", schema = "dbmanager")
public class Database {
@Id
@NotNull
@Column(name = "id_database", unique = true)
private String id;
@Column(name = "database_url")
private String databaseUrl;
@Column(name = "database_user")
private String databaseUser;
@Column(name = "database_password")
private String databasePassword;
@OneToMany(mappedBy = "database")
private Set<Table> tables;
}
表类:
@Entity
@javax.persistence.Table(name = "data_base_table", schema = "dbmanager")
public class Table {
@Id
@NotNull
@Column(name = "id_table", unique = true)
private String id;
@Column(name = "table_name")
@NotNull
private String name;
@Column(name = "table_visible")
private Integer visible;
@ManyToOne(fetch = FetchType.LAZY)
@NotFound(action = NotFoundAction.IGNORE)
@JoinColumn(name = "id_database")
private Database database = new Database();
@OneToMany(mappedBy = "table")
private Set<Field> fields;
}
字段类
@Entity
@javax.persistence.Table(name = "table_field", schema = "dbmanager")
public class Field {
@Id
@NotNull
@Column(name = "id_field", unique = true)
private String id;
@Column(name = "field_name")
@NotNull
private String name;
@Column(name = "field_visible")
@NotNull
private Integer visible;
@ManyToOne(fetch = FetchType.LAZY)
@NotFound(action = NotFoundAction.IGNORE)
@JoinColumn(name = "id_table")
private Table table = new Table();
}