我正在尝试在Spring-data-jpa中创建一个查询,以便Person
的{{1}}找到Address
实体。 id
与Person
有OneToOne关系,并且都有Address
作为主键。
id
我认为方法名称public abstract class AbstractEntity{
@Id
Long id;
}
public class Person extends AbstractEntity {
@OneToOne
Address address;
}
public class Address extends AbstractEntity {
}
public interface PersonRepository implements JpaRepository<Person, Long> {
Person findByAddressId(Long addressId); // Throws cannot create metamodel exception
Person findByAddress_Id(Long addressId); // Throws cannot create metamodel exception
}
和findByAddressId
对于Spring数据jpa查询查询策略不明确,因为findByAddress_Id
和Person
实体都有{{ 1}}作为他们的属性。
是否可以在Spring-data-jpa中编写查询以通过子属性查找父实体,其中父级和子级都具有相同的属性,而无需编写SQL?