Last active
January 25, 2018 21:20
-
-
Save fbaligand/5176060 to your computer and use it in GitHub Desktop.
Composant Java permettant de dire à dozer de manière générale, de ne pas copier les collections Hibernate non initialisées
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dozer; | |
import org.dozer.CustomFieldMapper; | |
import org.dozer.classmap.ClassMap; | |
import org.dozer.fieldmap.FieldMap; | |
import org.hibernate.Hibernate; | |
/** | |
* FieldMapper Dozer permettant de désactiver la copie des proxys Hibernate non initialisés (entité ou collection) | |
*/ | |
public class DisableLazyLoadingDozerFieldMapper implements CustomFieldMapper { | |
/** | |
* Si le champ n'est pas un proxy Hibernate ou est un proxy Hibernate initialisé, alors on laisse le mapping Dozer par défaut. | |
* Sinon, on retourne false, ce qui dit à Dozer de ne pas mapper ce champ. | |
*/ | |
public boolean mapField(Object source, Object destination, Object sourceFieldValue, ClassMap classMap, FieldMap fieldMapping) { | |
return Hibernate.isInitialized(sourceFieldValue); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment