Monday 15 June 2015

java - How does lazy fetching work in Hibernate? -


I have configured my userDetails class with slowness, and I have also configured my settings for lazy fetching. I'm running this code:

  userDetails user = new userDetails (); User.setUserName ("Fenil"); Address address = new address (); Address.setCity ("Baroda"); Address.setState ("Gujarat"); . User.getListOfAddress () add (address); SessionFastria sessionFactor = new configuration (). Configure (). BuildSessionFactory (); Session session = sessionfactory.open session (); Session.beginTransaction (); Session.save (user); Println (user.getName ()); // sop1 session.getTransaction (). Commit (); Session.close (); Println (user.getName ()); // sop2  

When I run the code above, I give the value of the username, but if I replace the SOAP line immediately after the session. Closing () So it's throwing an exception.

My question is:

If I print the sop1 line before closing the session, then I should give the user name, and after closing the session, the line marked sop2 An exception should be thrown, but instead it is refunding the value of the username.

Sluggish embrace still receives only once, stays the result for later calls. During your second call, the data has already been brought, so it can be returned even after the session is closed.


No comments:

Post a Comment