【发布时间】:2019-01-31 20:59:32
【问题描述】:
嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为“cityDao”的 bean 时出错:调用 init 方法失败;嵌套异常是 java.lang.IllegalArgumentException:无法为方法 public abstract java.util.List com.server.repository.location.CityDao.findAllWithCountry() 创建查询!没有找到类型 City 的属性 findAllWithCountry!
@Transactional
public interface CityDao extends JpaRepository<City, Integer> {
@EntityGraph(attributePaths = "country")
List<City> findAllWithCountry(); //this one does not work
@EntityGraph(attributePaths = "country")
City findOneWithCountryById(int id); //this one works
}
实体:
@Entity
@Table(name = "city", uniqueConstraints = {
@UniqueConstraint(columnNames = {"country", "city_name", "latitude", "longitude"})
})
@Data
public class City {
@ManyToOne(fetch = FetchType.LAZY)
@NotNull
@JoinColumn(name = "country")
private Country country;
}
我正在尝试实现 @EntityGraph 以提高 API 性能。
第一种方法抛出BeanCreationException,而第二种方法正在运行。唯一的区别是第一个返回一个集合,第二个返回一个实体。有办法解决吗?
【问题讨论】:
标签: hibernate spring-boot spring-data-jpa