查询以按子属性查找父实体,其中Parent也具有相同的属性,在spring数据jpa中

时间:2014-01-30 16:26:08

标签: spring-data-jpa

我正在尝试在Spring-data-jpa中创建一个查询,以便Person的{​​{1}}找到Address实体。 idPerson有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_IdPerson实体都有{{ 1}}作为他们的属性。

是否可以在Spring-data-jpa中编写查询以通过子属性查找父实体,其中父级和子级都具有相同的属性,而无需编写SQL?

0 个答案:

没有答案