【发布时间】:2016-11-16 04:22:16
【问题描述】:
我有 Object Master Location 和 MasterCountries
MasterLocation.java
@Entity
@Table(name = "master_location", schema = "public", catalog = "master_db")
@NamedEntityGraphs({
@NamedEntityGraph(name = "MasterLocation.joinsWithMasterCountries",attributeNodes = {
@NamedAttributeNode("masterCountriesByCountryCode")
}),
@NamedEntityGraph(name = "MasterLocation.noJoins",attributeNodes = {})
})
public class MasterLocation {
private String locationCode;
private String locationName;
private String countryCode;
private Integer agencyCode;
private String port;
private String place;
private String userId;
private Timestamp dateCreated;
private Timestamp lastModified;
private String portRefFrom;
private String portRefTo;
private String valid;
private String regionCode;
private String bookingRef;
private MasterCountries masterCountriesByCountryCode;
@ManyToOne(fetch = FetchType.LAZY)
@NotFound(action = NotFoundAction.IGNORE)
@JoinColumn(referencedColumnName = "iso_3166_1_alpha_2_code", name = "country_Code")
public MasterCountries getMasterCountriesByCountryCode() {
return masterCountriesByCountryCode;
}
}
MasterLocationRepository.java
@Repository
public interface MasterLocationRepository extends JpaRepository<MasterLocation, Integer> {
@EntityGraph(value = "MasterLocation.noJoins",type = EntityGraph.EntityGraphType.LOAD)
Page<MasterLocation> findByLocationNameLikeIgnoreCase(String locationName, Pageable pageable);
}
为什么对象 MasterCountries 仍会在 findByLocationNameLikeIgnoreCase 上加载?如何在此存储库中禁用 Fetch MasterCountries?
谢谢
【问题讨论】:
-
那是你的真实实体吗?
@Id在哪里?还应该有更多的吸气剂...请添加完整的实体而不是 sn-p。
标签: spring-boot spring-data-jpa