Hibernate save lazily fetched entity via stateless

2019-06-10 09:30发布

For optimization purposes I would like to update some entities with an hibernate stateless session.

These entities, however, are loaded from a "classical" session (I need cache feature to load my entities quicker). All of this could be good but some of my entities are lazily initialized, so their class name is something like : myentity_$$_javassist_22. Thus, my stateless session does not want to update my entity.

Is there a way to transform a lazily initialized entity to a loaded entity ?

thank you

1条回答
不美不萌又怎样
2楼-- · 2019-06-10 09:56

If you manually fetch all the lazy-loaded entities before giving them to your stateless session it will work (no more proxies). But it could cost a lot as it would generate many queries to load the full object graph.

Either you fetch them before with Hibernate.initialize(lazyEntity) for instance, either you kill them with proxy-killing methods (but you will save null: probably it is not what you want).

Check this other question about Hibernate stateless session to see if it is a good solution for your problem Using StatelessSession for Batch processing

查看更多
登录 后发表回答