简体   繁体   English

无法懒惰地加载JPA关系

[英]Unable to lazily load JPA relationships

I'm working with Jhipster. 我正在和Jhipster合作。 I'm not being able to fetch Customers lazily. 我无法懒得取客户。

I have made a JDL like so... 我这样做了一个JDL ......

 PROPERTY
 id
 ...

 CUSTOMER
 id
 ...

 CUSTOMER_PROPERTY
 id
 customer_id
 property_id
 value

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

My Domains 我的域名

Customer.java Customer.java

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

Property.java no mapping Property.java没有映射

CustomerProperty.java CustomerProperty.java

 @ManyToOne
 private Property property;

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

I have already tried to explicit set fetch = FetchType.LAZY but it keeps bringing the full complete Customer object with all CustomerProperties List 我已经尝试过显式设置fetch = FetchType.LAZY,但它不断带来所有CustomerProperties列表的完整Customer对象

I would like to understand why the fetch it's not working 我想了解为什么获取它不起作用

Debugging is not a good mechanism for evaluation if a collection has been lazily loaded or not. 如果集合已经延迟加载,则调试不是一种很好的评估机制。 The debugger itself may trigger initialization. 调试器本身可能会触发初始化。

Instead of using debugger use the 而不是使用调试器使用

org.hibernate.Hibernate.isInitialized(yourCollection) 

to verify if it has been initialized after the loading of your entity. 验证在加载实体后是否已初始化。

If this method return false but you still suspect that at later point the collection is initialize you should search the error in a possible subsequent call (somewhere else). 如果此方法返回false,但您仍然怀疑在稍后集合初始化时,您应该在可能的后续调用中搜索错误(在其他地方)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM