-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Session saves twice??
PostPosted: Fri Feb 04, 2005 1:29 pm 
Newbie

Joined: Fri Feb 04, 2005 1:16 pm
Posts: 1
Location: Orlando, FL
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:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.