@NamedQuery尝试通过相关实体属性获取实体和相关实体(@OneToOne关系)

时间:2019-01-17 22:51:07

标签: spring-data-jpa one-to-one named-query

有两个实体:

@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;
  1. 目标是通过外部ID返回AccountAccountDetials。该程序由于错误而无法运行: 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映射和查询的不同变体,但是似乎没有任何效果。

  2. 第二个问题是是否可以让AccountDetails引用与Account相同的ID。我想摆脱accDetId,而只将这些实体存储为其父实体的相同UUID。

0 个答案:

没有答案