Quote:
But the problem is that there is no getTransaction() method associated with the Session object (org.hibernate.Session).
Are you positive that you didn't import org.hibernate
.classic.Session by any chance? Netbeans offers that first, if you use code assist, for example.
org.hibernate.classic.Session does not have the getTransaction() method, but org.hibernate.Session does.
Quote:
Do I have to close the session each time I try to access the DB?
I guess that pretty much depends on how you use Hibernate. You don't even have to bother with starting transactions in a managed environment.
If you are not in a managed environment, I think by default commit and rollback will close the session for you. You can change that behaviour, though.
See the API doc for ThreadLocalSessionContext, which is the default CurrentSessionContext.
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/context/ThreadLocalSessionContext.html
Roland