-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Use case
Problem
In this article: https://medium.com/cloud-workers/mapstruct-and-hibernate-jpa-lazy-loading-1c1c6f416e, the author uses the Condition of mapstruct to handle the lazy loading problem of Hibernate.
The lazy loading problem discussed in this article is the classic feature of Hibernate2+, for many-to-one association, it is a uninitialized proxy object; for one-to-many/many-to-many association, it is special uninitialized collection implementation provided by hibernate. Although the proxy or collection is uninitialized, developer can safely get it and then use Hibernate.isInitialized(obj) to check whether it is initialized.
However, since Hibernate3, another new lazy loading mechanism is provided. Not only the association properties, but also the scalar properties can be lazy. please view the link https://stackoverflow.com/questions/19610085/using-lazy-for-properties-in-hibernate, this feature is designed for lob scalar properties.
Unfortunately, for this uninitialized scalar properties, exception will be immediately raised when the getter is called, the developer must use Hibernate.isPropertyInitialized(obj, propertyName) to check it before access it.
So the solution in this article cannot work with lazy scalar property in Hibernate3+.
Expected behavior
Support a new annotation @PropertyCondition, it can be used like this
@PropertyCondition
public boolean isAccessible(MyData data, String propertyName) {
return Hibernate.isPropertyInitialized(data, propertyName);
}Generated Code
No response
Possible workarounds
No response
MapStruct Version
No response