有了jpa,我可以让类a中的一个字段成为类b的一个一个一个,然后类b中的一个字段成为类a的一个一个一个吗?

okxuctiv  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(200)

我有两个类,其中类a有一个非空字段,它是类b的一个。
现在我希望在类b中有一个字段连接到一个类a示例。
例如,假设一个人正在从图书馆拿书。每本书对用户来说都有一个OneOne,而且不会改变;但是,用户有一个字段只连接到一本名为 CurrentlyReadingBook 这可能会改变。
最初将person对象存储到book的user字段中的onetoone是可以的,但是当我尝试将book存储到person对象中的onetoone时,我得到了一个stackoverflow错误,我假设这是由于两个类只是来回调用,试图无限获取数据。
所以我想知道,如果我想做的只是使用2个单独的表/类是可能的?我考虑过用一个表c,然后把信息放进去,或者只存储图书的id而不是图书对象本身,但是我觉得这两个方法是没有必要的,我认为应该有一种方法,只使用我拥有的两个表/类。
非常感谢您提供的任何信息/帮助。
这里是错误的情况下,这有助于在某种程度上

Info:   Exception Description: Unable to deploy PersistenceUnit [PersistenceUnitA] in invalid state [DeployFailed].
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Deployment of PersistenceUnit [PersistenceUnitA] failed. Close all factories for this PersistenceUnit.
Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------
Exception [EclipseLink-168] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Problem in creating new instance using the default constructor.  The default constructor triggered an exception.
Internal Exception: java.lang.reflect.InvocationTargetException
Target Invocation Exception: java.lang.StackOverflowError
Descriptor: RelationalDescriptor(A --> [DatabaseTable(A)])
Exception [EclipseLink-168] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Problem in creating new instance using the default constructor.  The default constructor triggered an exception.
Internal Exception: java.lang.reflect.InvocationTargetException
Target Invocation Exception: java.lang.StackOverflowError
Descriptor: RelationalDescriptor(B --> [DatabaseTable(B)])
Exception [EclipseLink-168] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Problem in creating new instance using the default constructor.  The default constructor triggered an exception.
Internal Exception: java.lang.reflect.InvocationTargetException
Target Invocation Exception: java.lang.StackOverflowError
Descriptor: RelationalDescriptor(C --> [DatabaseTable(C)])
Exception [EclipseLink-168] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Problem in creating new instance using the default constructor.  The default constructor triggered an exception.
Internal Exception: java.lang.reflect.InvocationTargetException
Target Invocation Exception: java.lang.StackOverflowError
Descriptor: RelationalDescriptor(D --> [DatabaseTable(D)])
Runtime Exceptions: 
---------------------------------------------------------

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题