无法懒惰地加载JPA关系

问题描述 投票:3回答:1

我正在和Jhipster合作。我无法懒得取客户。

我这样做了一个JDL ......

 PROPERTY
 id
 ...

 CUSTOMER
 id
 ...

 CUSTOMER_PROPERTY
 id
 customer_id
 property_id
 value

 relationship OneToMany {
    Customer to CustomerProperty                    
 }
 relationship ManyToOne {
    CustomerProperty to Property    
 }

我的域名

customer.Java

 @OneToMany(mappedBy = "customer", fetch = FetchType.LAZY)
 @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
 private Set<CustomerProperty> customerProperties = new HashSet<>();

Property.java没有映射

customer property.Java

 @ManyToOne
 private Property property;

 @ManyToOne
 @JsonIgnoreProperties("customerProperties")
 private Customer customer;

我已经尝试过显式设置fetch = FetchType.LAZY,但它不断带来所有CustomerProperties列表的完整Customer对象

我想了解为什么获取它不起作用

java database hibernate jpa persistence
1个回答
2
投票

如果集合已经延迟加载,则调试不是一种很好的评估机制。调试器本身可能会触发初始化。

而不是使用调试器使用

org.hibernate.Hibernate.isInitialized(yourCollection) 

验证在加载实体后是否已初始化。

如果此方法返回false,但您仍然怀疑在稍后集合初始化时,您应该在可能的后续调用中搜索错误(在其他地方)。

© www.soinside.com 2019 - 2024. All rights reserved.