Home Hibernate/JPA refresh whole collection
Reply: 0

Hibernate/JPA refresh whole collection

user957
1#
user957 Published in July 22, 2018, 10:26 am

I have a Lazy load @OneToMany

@JsonIgnore
@OneToMany(mappedBy = "order", cascade = CascadeType.ALL)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private List<OrderItem> orderItems = new ArrayList<>();

After a long operation, I want to refresh the orderItems entities.

I have to loop over the childs and refresh like below:

for (OrderItem orderItem : order.getOrderItems()) {
   entityManager.refresh(orderItem);
}

I believe this is very not efficient, because it is trying to refresh the entity one by one, which mean it fires the SQL one by one.

I believe how hibernate works when we call proxy wrapper getOrderItems, it is just fire one SQL to select the records by the parent's foreign key. This is more efficient.

Am I able to refresh the whole list in this way?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311646 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO