【发布时间】:2015-07-10 19:06:07
【问题描述】:
我正在尝试使用 JPA (EclipseLink) 为一个非常简单的 OneToOne 关系建模,但我得到了一个异常 java.lang.NoSuchFieldException 的描述“访问主键对象时发生内部错误”。
TableA 与 TableB 具有 OneToOne 关系。我需要在我的 TableA 实体上有一个 TableB 实体。
我的尝试
@NamedNativeQueries(... ommitted for breviety ...)
@Entity
@Table(name = "TableA")
@Cache(isolation = CacheIsolationType.ISOLATED)
public class TableA implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private TableA_Id id; //Code is part of the composite embeded
@OneToOne
@JoinColumn(name = "CODE", insertable = false, updatable = false)
private TableB b;
//getters + setters
@NamedNativeQueries(... ommitted for breviety ...)
@Entity
@Table(name = "TableB")
@Cache(isolation = CacheIsolationType.ISOLATED)
public class TableB implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "CODE")
private String code;
@Column(name = "DESCRIPTION")
private String description;
//getters + setters
例外:
Exception [EclipseLink-0] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: An internal error occurred accessing the primary key object [202].
Internal Exception: java.lang.NoSuchFieldException: b
Descriptor: RelationalDescriptor(com.foo.TableA --> [DatabaseTable(TableA)])
这可能值得注意; TableA和TableB上的代码之间没有定义外键;我没有能力改变它。
【问题讨论】: