有两个实体:
@Entity(name = "Account")
@Table(name = "accounts")
@NamedQuery(name = "findAccountByExtId",
query = "SELECT a " +
"FROM Account a " +
"WHERE a.accountDetails.extId = :extId " +
"AND a.deletedAt IS NULL")
public class Account extends DeletableAudit {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private UUID id;
@OneToOne(mappedBy = "parent", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private AccountDetails accountDetails;
和
@Entity(name = "AccountDetails")
@Table(name = "account_details")
public class AccountDetails extends DeletableAudit {
private static final long serialVersionUID = -1L;
@Id
@GeneratedValue
private Integer accDetId;
@OneToOne
@JoinColumn(name = "fk_account")
private Account parent;
@Column
private String extId;
目标是通过外部ID返回Account
和AccountDetials
。该程序由于错误而无法运行:
Failed to create query for method public abstract p.j.o.d.d.Account p.j.o.d.r.AccountRepository.findAccountByExtId(java.lang.String)! No property extId found for type Account!
已经尝试了@OneToOne
映射和查询的不同变体,但是似乎没有任何效果。
第二个问题是是否可以让AccountDetails
引用与Account
相同的ID。我想摆脱accDetId
,而只将这些实体存储为其父实体的相同UUID。