简体   繁体   中英

Hibernate objects and Java reflection

I am lazily loading an object from hibernate using the following line of code Object object = session.load(Class.forName(javaType), objectId);

If I print object.getClass().getSimpleName() it displays the name of the hibernate proxy and not my implementation class as expected.

However If I then use reflection on this proxy object to return an attribute called children as follows: List children = (List) object.getClass().getMethod("getChildren", new Class[ {}).invoke(object, new Object[]{});

It is returning a list of objects where object.getClass().getSimpleName() on any of the objects returns the implementation class name. Why are these objects not returning the proxy object name?

列表本身可以延迟加载,但是如果枚举元素,则需要执行sql查询,并且为每个元素创建代理都不会提高性能(相反)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM