Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.05
Name and version of the database you are using: MySQL 4.1.16
We're about to set up persistence for a 2-tier Swing application that uses Hibernate to read and write from a MySQL database. This is a multi-user system, so we will need to heavily rely on versioning and pessimistic locking to ensure fresh data.
From posts on this forum, it sounds like a single session for the whole process is the best way to go, so that we can have process-scoped identity. Before we get started on the project, I'd like to ask a few questions here to make sure we don't get into trouble down the road.
1) The Hibernate docs state that all HibernateExceptions are fatal. In a single session model, what is the best way to handle these exceptions? We cannot simply reload the objects from the database, because we need to maintain process-scoped identity.
2) Assuming that we come up with a reasonable solution for #1, I have a specific question about the StaleDataException. If we call session.lock(object, LockMode.READ) and get a StaleDataException (which will happen quite often), can we safely just use refresh() to update our object, or do we need to consider this fatal?
3) Other than a HibernateException or running out of memory, are there any other cases where we need to close the session?
4) If we do a fetch from the database and we already have some of the resulting items as persistent objects in our session, are our persistent objects refreshed? If not, what happens? Do we simply discard the values from the database?