Why does Hibernate seem to be for short classes?

I know this is a subjective question, but why does Hibernate seem to be designed for short sessions? As a rule, in my applications I create a DAO to abstract the data layer, but since I cannot predict how entity objects will be used, some of its collections will be loaded lazy, or I must say that they do not load after the session is closed.

Why didn’t they design it so that it automatically resumed the session, or did sessions always remain open?

+3
source share
6 answers

After you move out of the transaction boundary, you cannot get into the database again without starting a new transaction. Just in case long-term transactions are a bad thing (tm).

I think you want a lazy boot object from your view - look here for some options. I prefer to determine exactly which part of the feature map will be returned by my session processing methods. I find this facilitates unit test and performance testing of my business level.

+4
source

I was working on a desktop application using EJB and Hibernate. We had to install lazy=falseeverywhere, because when objects become serialized, they lose the ability to be extracted from the backend. This is how it happens, unfortunately.

, , .

+2

OpenSessionInView, ( ), , . , .

+1

, .

+1

- , , . , , , . , - - , , , .

MS ADO.NET, , , - , , , .

0

Hibernate . . . , , , , . , "" , , , .

If it were magical to resume sessions in non-webapps, I think that the complexity of learning the structure will greatly reduce the benefits.

0
source

Source: https://habr.com/ru/post/1697426/


All Articles