I have a problem that is causing the session (apparently) to save twice. I have isolated the call to the service class with the code below which calls save. This section of code is indeed only called once. In the logs the first save is fine, then it immediately tries to save a second time. Then the code exits as expected.
Hibernate version:
2.0
Mapping documents:
220 mapping files, all of which are fine
Code between sessionFactory.openSession() and session.close():
I use the recommeded singleton HibernateUtil for retrieving the session. Here is the code that is creating the save request:
try {
Session session = HibernateUtil.currentSession();
//session.setFlushMode(FlushMode.AUTO);
Transaction tx = session.beginTransaction();
if (action.equalsIgnoreCase("NEW")) {
session.save(obj);
if (logger.isDebugEnabled()) {
logger.debug("**** Inserted " + obj.getClass() +
" using HibernateService! ***");
}
}
else if (action.equalsIgnoreCase("CREATE")) {
session.save(obj);
if (logger.isDebugEnabled()) {
logger.debug("**** Created " + obj.getClass() +
" using HibernateService! ***");
}
}
else if (action.equalsIgnoreCase("UPDATE")) {
session.update(obj);
if (logger.isDebugEnabled()) {
logger.debug("**** Updated " + obj.getClass() +
" using HibernateService! ***");
}
}
else if (action.equalsIgnoreCase("CHANGED")) {
session.update(obj);
if (logger.isDebugEnabled()) {
logger.debug("**** Changed " + obj.getClass() +
" using HibernateService! ***");
}
}
else if (action.equalsIgnoreCase("DELETE")) {
session.delete(obj);
if (logger.isDebugEnabled()) {
logger.debug("**** Deleted " + obj.getClass() +
" using HibernateService! ***");
}
} else {
logger.warn("***************************************************");
logger.warn("***WARNING: no action was defined for this topic***");
logger.warn("*** topic is: " + obj.getClass() + "(" + action + ") ***");
logger.warn("***************************************************");
}
tx.commit();
//success = tx.wasCommitted();
//session.flush();
success = true;
if (tx.wasRolledBack()) {
success = false;
logger.warn("**********************************************");
logger.warn("WARNING: Hibernate transaction was rolled back.");
logger.warn("**********************************************");
}
HibernateUtil.closeSession();
}
catch (HibernateException he) {
logger.error("***********************************");
logger.error("ERROR Exception: " + he.getMessage());
//he.printStackTrace();
logger.error("***********************************");
}
Full stack trace of any exception that occurs:
I get, of course, a primary key violation from SQL Server.
Name and version of the database you are using:
MS SQL Server 2000, sp 3, with XA enabled
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
|