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

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

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

  1. Info: Exception Description: Unable to deploy PersistenceUnit [PersistenceUnitA] in invalid state [DeployFailed].
  2. Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.EntityManagerSetupException
  3. Exception Description: Deployment of PersistenceUnit [PersistenceUnitA] failed. Close all factories for this PersistenceUnit.
  4. Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.IntegrityException
  5. Descriptor Exceptions:
  6. ---------------------------------------------------------
  7. Exception [EclipseLink-168] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DescriptorException
  8. Exception Description: Problem in creating new instance using the default constructor. The default constructor triggered an exception.
  9. Internal Exception: java.lang.reflect.InvocationTargetException
  10. Target Invocation Exception: java.lang.StackOverflowError
  11. Descriptor: RelationalDescriptor(A --> [DatabaseTable(A)])
  12. Exception [EclipseLink-168] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DescriptorException
  13. Exception Description: Problem in creating new instance using the default constructor. The default constructor triggered an exception.
  14. Internal Exception: java.lang.reflect.InvocationTargetException
  15. Target Invocation Exception: java.lang.StackOverflowError
  16. Descriptor: RelationalDescriptor(B --> [DatabaseTable(B)])
  17. Exception [EclipseLink-168] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DescriptorException
  18. Exception Description: Problem in creating new instance using the default constructor. The default constructor triggered an exception.
  19. Internal Exception: java.lang.reflect.InvocationTargetException
  20. Target Invocation Exception: java.lang.StackOverflowError
  21. Descriptor: RelationalDescriptor(C --> [DatabaseTable(C)])
  22. Exception [EclipseLink-168] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DescriptorException
  23. Exception Description: Problem in creating new instance using the default constructor. The default constructor triggered an exception.
  24. Internal Exception: java.lang.reflect.InvocationTargetException
  25. Target Invocation Exception: java.lang.StackOverflowError
  26. Descriptor: RelationalDescriptor(D --> [DatabaseTable(D)])
  27. Runtime Exceptions:
  28. ---------------------------------------------------------

暂无答案!

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

相关问题