Created
December 16, 2013 01:48
-
-
Save yanhua365/7981231 to your computer and use it in GitHub Desktop.
对Hibernate的对象明确指定加载哪些关联属性,
避免在session关闭后访问出现LazyInitialize错误。
This file contains hidden or 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
public void initialize(Object entity, String... properties){ | |
for(String name : properties){ | |
try { | |
String property = BeanUtils.getProperty(entity, name); | |
Hibernate.initialize(property); | |
} catch (Throwable e) { | |
logger.error("initialize lazy property occurs error.", e); | |
throw Throwables.propagate(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment