user93796
user93796

Reputation: 18379

hibernate DAO design

do i have to open and close session and transcation in each function (make object ,delete object ,findbyID)

can u give me a DAO implenetation for findall (lazy initialization ).

Upvotes: 1

Views: 862

Answers (1)

Stefan Steinegger
Stefan Steinegger

Reputation: 64628

You should have a transaction for each complete business operation. I For instance: The operation includes selecting some values, updating it and inserting others. If each of the elementary operations create their own transaction, you will fail writing a multi-user application.

You should create the session at the beginning of the business operation, create a transaction, then perform all the operations (you "functions") within that transaction, and commit or rollback them all together.

Transactions are defined in the business layer.

Upvotes: 3

Related Questions