How can I get objects out of sleep and into memory. I'm having problems with my session

I have a pretty huge project where I am trying to modify data in memory. Basically, I have a large collection of objects that contain primitives and other objects that hibernate. Large sections of non-dao code rely on lazy loading through hibernation to hydrate objects on the fly. However, since everything exists in memory, my object is not loaded and I get a lazy load hibernate exception.

I could just manually hibernate lazy loading by going to hibernate and wetting the hibernation object manually, but the object graph for that object is huge, containing hundreds of types that will need to be initialized and set. This seems impractical and I am looking for a viable solution to this problem. If anyone has any advice, hints, solutions or stories related to this issue or similar problems, I would be very grateful.

Many thanks.

0


a source to share


3 answers


If you are handling sessions manually, try passing object IDs (row IDs in the database) instead of full objects. Then provision the database by reading when you want to get the complete ORM object, and only store the ORM object in a limited amount so that it can be garbage collected when you're done with it. This will probably save you some memory.



This has the side effect of also limiting the amount of time you need an open session. As you can open sessions (I would recommend a factory session) and close them as needed. However, I think there could be significant database success for opening and closing sessions (I think the underlying transaction is the real problem). You might want to look into JPA, which I understand does not require a transaction to be read. Spring also has several useful features to automate the transaction and session management they can explore.

+1


a source


The session is probably already closed. Try to keep the session open when the data is lazy loaded, or if that is not possible, load the load by specifying the lazy = "false" (lazy = "true") attribute on the collection.



0


a source


The most common reason LazyInitializationException

is that the hibernation session has been closed. Keep your hibernate session open and you should be fine.

Note that if you are using Spring HibernateTemplate

to load objects, the objects you load will necessarily be detached. If you are building a webapp with Spring MVC then it is easy to use OpenSessionInViewInterceptor .

0


a source







All Articles