I am writing an utility class which can load the lazy loaded properties of an entity on demand!
public Entity loadEntity(Long id,String eagerFetchPropertyName){
Entity e = session.load(id); //psudo code
if e.eagerFetchPropertyName Loaded and equals(eagerFetchPropertyName)
initialize the property and load it as requested
if e.eagerFetchPropertyName and not equals(eagerFetchPropertyName)
don't load it.
}
Idea is
- Call all getters and check whether they are annotated with Lazy Load or any other way to find Lazy Loaded. If yes, follow above thing
- Call getter with passed propertyName, if it's present then load it otherwise leave it using reflection
How do I know that specific property/collection in Entity is LazyInitialized? Anyway to read annotation on the entity object or any other way? Couldn't figure it out!
Aucun commentaire:
Enregistrer un commentaire