it's almost the same code the only real difference is in these lines
Code:
Session session = factory.openSession();
Code:
factory.getCurrentSession().beginTransaction();
The second line is correct but the way it's coded is actually just confusing code. We should not chain method calls like this it makes code harder to understand.
If I was to write that example myself this is what it would look like
Code:
Session session = factory.getCurrentSession();
Transaction tx = session.beginTransaction();
so essentially the new version above is the same as the second example just more readable.
Code:
factory.getCurrentSession().beginTransaction();
You can now see they are both getting a session and a transaction. Now the actual difference is that factory.openSession() always returns a new session. Where as factory.getCurrentSession() will return the current session or a new one if one is not present.
Other than that difference they are the same exact code. One is just poorly written.