-
Notifications
You must be signed in to change notification settings - Fork 693
Expose Datastore LazyUtil #2418
Comments
@BenDol could you clarify your use case? I think we will be able to help you better if we have more info. Thanks |
@dmitry-s sure, so the main use case I have at the moment is being able to determine a beans loaded state on its properties for serializing the object. When the User user = userRepository.findByName("John Doe");
Set<Group> groupProxy = user.getGroups();
if(LazyUtil.isLazyAndNotLoaded(groupProxy)) {
LazyUtil.SimpleLazyDynamicInvocationHandler ih = LazyUtil.getProxy(groupProxy);
Class type = ih.getType();
// override proxy set before serialization (avoid lazy loading all data upon serialization)
user.setGroups((Set<Group>) type.newInstance());
} Here I am replacing the user groups with a new placeholder instance to void invoking the lazy load when its serialized. Does that help? Let me know if there is anything else I can clarify. Most appreciated! |
@BenDol we think we can add a method to DatastoreOperations to support this. Just to clarify, what do you think should happen when you deserialize such object? |
Some serialization tools we use will invoke the lazy load on our objects causing an n+1 scenario. This is simply to avoid that, we check if the field was already lazy loaded and if so we can include it in the serialization otherwise we ignore it. It would be helpful to just open up the LazyUtil since it solves my issue. No need to add something to the DatastoreOperations for my usecase. Unless there is more to it. |
Just going through some old unresponded issues.... |
Expose spring datastore LazyUtil or an explaination why this shouldn't be exposed for use? Some utility methods like LazyUtil.isLazyAndNotLoaded would be very useful for me to process data for transactions, etc.
Basic example use case:
This would mean exposing the invocation handler and making use the SimpleDynamicIncovationHandler stored the proxies type. From my testing I was unable to get the proxies underlying type any other way.
LazyUtil.java
The text was updated successfully, but these errors were encountered: