首先,您不能从CustomerRepository返回CustomerAddress。
一些替代方案是
- 要根据中的姓氏检索CustomerAddress
CustomerRepository
,您可以执行以下操作
Customer findByPrefBillAddressUid_LastName(String lastName);
spring-
data将制定查询,您不需要
@Query。但是请注意,如果
Customer不是,则返回类型
CustomerAddress。因此,您将获得具有正确的customerAddress的客户对象。
- 如果要返回CustomerAddress,则需要创建CustomerAddressRepository并编写这样的方法
CustomerAddress findByLastName(String lastName);
- 使用投影 创建这样的界面
interface CustomerShort {CustomerAddress getPrefBillAddressUid();}
然后您的CustomerRepository需要使用这样的方法
interface CustomerRepository extends CRUDRepository<Customer, UUID> { Collection<CustomerShort> findByPrefBillAddressUid_LastName(String lastName);}


