我使用Java + Spring + Hibernate的@OneToOne隨着@JoinColumn只保存在UUID,而不是整個對象
當測試下面的代碼,我得到一個錯誤:
javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.XXX.XXX.entity.Policy.id
@Entity
@Table(name = "assignment")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Assignment extends BaseEntity {
@Id
@Column(name = "id")
@Type(type = "pg-uuid")
@NotTracked
private UUID id;
@OneToOne(targetEntity = Policy.class)
@JoinColumn(name = "policy_id", nullable = false, referencedColumnName = "policy_id")
@OnDelete(action = OnDeleteAction.CASCADE)
@TrackedEntity(isIdentityField = true)
private UUID policyID;
}
@Entity
@Table(name = "policy")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "policy")
@Inheritance(strategy = InheritanceType.JOINED)
public class Policy extends BaseEntity {
@Id
@Column(name = "policy_id")
@Type(type = "pg-uuid")
@NotTracked
private UUID id;
...
...
..
}
當改變從UUID
的private UUID policyID;
到Policy
,它的工作就好了,有沒有一種方法來設置莫名其妙內政策對特定對象的引用作爲ID,而不是等待策略的整個對象的分配對象裏面?