嵌入式表的JPA存储库

时间:2019-10-05 15:28:19

标签: spring hibernate jpa

我有以下实体:

@Entity
@Table(name = "ACCOUNT")
public class Account {
 @Column(name = "ADDRESS_ID")
 @CollectionTable(name = "ACCOUNT_ADDRESS", joinColumns = 
 @JoinColumnt(name="ACCOUNT_ID")
 private List<Address> adresses;
 .....

}

@Embeddable
public class Address {
@Column(name = "ADDRESS_ID")
private int addressId;
....

}

现在,我可以通过扩展JpaRepository轻松创建 AccountRepository 并通过它访问 Accounts 。但是,获取地址的最有效方法是什么?

我想访问地址表以获得地址:

Pageable<Address> findAddresses(String city, String zipcode) 

创建普通存储库

public inerface AddressRepository extends JpaRepository<Address, Long>

导致运行时异常:

Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: The given domain class does not contain 
an id attribute!

如何处理?

0 个答案:

没有答案