-->
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.  [ 5 posts ] 
Author Message
 Post subject: Rollback after inserting of a new Object with HibernateExcep
PostPosted: Wed Mar 16, 2005 5:33 am 
Newbie

Joined: Wed Mar 16, 2005 5:15 am
Posts: 2
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

I want to save (first it hjas to insert it) a new instanceof NatuerlichePerson. The id is initially 0. Now I saveOrUpdate it. The Id in NatuerlichePerson is set to 1, but now an error occurs, because one field is null and the database demands to fill it. After the HibernateException has been thrown, I rollback it. The field is correctly filled and now I try it to saveOrUpdate it again. Unfortunately the Id in the classobject is not rollbacked to the initial state 0.
This seems to me a simple form, but if I build complex class hierarchies,
there is normally no way to rollback by the application developer. It must be made by Hibernate. Is there any solution?

Hibernate version:
2.1.8

Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class name="....NatuerlichePerson" table="kde_np">

<id name="Id" column="np_id" unsaved-value="0">
<generator class="native">
<param name="sequence">SEQ_KDE_NP_ID</param>
</generator>
</id>
.....


Code between sessionFactory.openSession() and session.close():
Transaction t=null;
try {
t = session.beginTransaction();
session.saveOrUpdate(o);
t.commit();
}
catch (HibernateException ex) {
logger.error(ex);
ex.printStackTrace();
if (null!=t)
t.rollback();
if (null!=showError) {
String sMessage = MessageFormat.format(
"Speichern [{0}] fehlerhaft.\n{0}", new Object[] { this });
showError.showError(sMessage, ex);
}
throw ex;
}


Full stack trace of any exception that occurs:
2005-03-16 09:07:29,250 DEBUG [main] hibernate.SQL (BatcherImpl.java:230) - insert into kde_np (np_name, np_vorname, np_geburtsdatum, np_sterbedatum, np_geburtsname, np_geburtsvorname, np_geburtsort, np_titel, np_namenszusatz, np_legitimation_art, np_legitimation_nummer, np_legitimation_behoerde, np_legitimation_datum, np_legitimation_gueltig_bis, np_anrede_id, np_geschlecht_id, np_familienstand_id, np_nation_id, np_gueterstand_id, np_rechtsform_id, np_anmerkungen, np_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2005-03-16 09:07:29,296 WARN [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:57) - SQL Error: 1400, SQLState: 23000
2005-03-16 09:07:29,296 ERROR [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:58) - ORA-01400: Einfügen von NULL in ("KNOWIS_WIVO"."KDE_NP"."NP_RECHTSFORM_ID") nicht möglich

2005-03-16 09:07:29,312 WARN [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:57) - SQL Error: 1400, SQLState: 23000
2005-03-16 09:07:29,312 ERROR [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:58) - ORA-01400: Einfügen von NULL in ("KNOWIS_WIVO"."KDE_NP"."NP_RECHTSFORM_ID") nicht möglich

2005-03-16 09:07:29,328 WARN [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:57) - SQL Error: 1400, SQLState: 23000
2005-03-16 09:07:29,328 ERROR [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:58) - ORA-01400: Einfügen von NULL in ("KNOWIS_WIVO"."KDE_NP"."NP_RECHTSFORM_ID") nicht möglich

2005-03-16 09:07:29,343 WARN [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:57) - SQL Error: 1400, SQLState: 23000
2005-03-16 09:07:29,359 ERROR [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:58) - ORA-01400: Einfügen von NULL in ("KNOWIS_WIVO"."KDE_NP"."NP_RECHTSFORM_ID") nicht möglich

2005-03-16 09:07:29,359 ERROR [main] impl.SessionImpl (SessionImpl.java:2400) - Could not synchronize database state with session
2005-03-16 09:07:29,359 ERROR [main] hibernate.DBController (DBController.java:315) - net.sf.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
net.sf.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at net.sf.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:73)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at net.sf.hibernate.impl.BatcherImpl.convert(BatcherImpl.java:328)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:135)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2392)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2261)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at de.knowis.helper.hibernate.DBController.saveDB(DBController.java:312)
at de.knowis.isfinancial.organisation.controller.DBPersonController.saveDBPerson(DBPersonController.java:180)
at de.knowis.isfinancial.organisation.controller.PersonController.saveDB(PersonController.java:113)
at de.knowis.isfinancial.organisation.swt.view.PersonEditorPart$7.run(PersonEditorPart.java:116)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:988)
at org.eclipse.ui.actions.RetargetAction.runWithEvent(RetargetAction.java:215)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:555)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:505)
at org.eclipse.jface.action.ActionContributionItem$7.handleEvent(ActionContributionItem.java:460)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2783)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2442)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1443)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1414)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:271)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:144)
at de.knowis.isfinancial.isgewerbe.isGewerbe.run(isGewerbe.java:120)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:335)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
at org.eclipse.core.launcher.Main.run(Main.java:704)
at org.eclipse.core.launcher.Main.main(Main.java:688)
Caused by: java.sql.BatchUpdateException: ORA-01400: Einfügen von NULL in ("KNOWIS_WIVO"."KDE_NP"."NP_RECHTSFORM_ID") nicht möglich

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4210)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:128)
... 32 more
2005-03-16 09:07:55,968 DEBUG [main] hibernate.SQL (BatcherImpl.java:230) - update kde_np set np_name=?, np_vorname=?, np_geburtsdatum=?, np_sterbedatum=?, np_geburtsname=?, np_geburtsvorname=?, np_geburtsort=?, np_titel=?, np_namenszusatz=?, np_legitimation_art=?, np_legitimation_nummer=?, np_legitimation_behoerde=?, np_legitimation_datum=?, np_legitimation_gueltig_bis=?, np_anrede_id=?, np_geschlecht_id=?, np_familienstand_id=?, np_nation_id=?, np_gueterstand_id=?, np_rechtsform_id=?, np_anmerkungen=? where np_id=?
2005-03-16 09:07:55,984 DEBUG [main] hibernate.SQL (BatcherImpl.java:230) - select natuerlich0_.np_id as np_id7_, natuerlich0_.np_name as np_name7_, natuerlich0_.np_vorname as np_vorname7_, natuerlich0_.np_geburtsdatum as np_gebur4_7_, natuerlich0_.np_sterbedatum as np_sterb5_7_, natuerlich0_.np_geburtsname as np_gebur6_7_, natuerlich0_.np_geburtsvorname as np_gebur7_7_, natuerlich0_.np_geburtsort as np_gebur8_7_, natuerlich0_.np_titel as np_titel7_, natuerlich0_.np_namenszusatz as np_name10_7_, natuerlich0_.np_legitimation_art as np_legi11_7_, natuerlich0_.np_legitimation_nummer as np_legi12_7_, natuerlich0_.np_legitimation_behoerde as np_legi13_7_, natuerlich0_.np_legitimation_datum as np_legi14_7_, natuerlich0_.np_legitimation_gueltig_bis as np_legi15_7_, natuerlich0_.np_anrede_id as np_anre16_7_, natuerlich0_.np_geschlecht_id as np_gesc17_7_, natuerlich0_.np_familienstand_id as np_fami18_7_, natuerlich0_.np_nation_id as np_nati19_7_, natuerlich0_.np_gueterstand_id as np_guet20_7_, natuerlich0_.np_rechtsform_id as np_rech21_7_, natuerlich0_.np_anmerkungen as np_anme22_7_, anredeitem1_.anrede_id as anrede_id0_, anredeitem1_.anrede_bezeichnung as anrede_b2_0_, geschlecht2_.geschlecht_id as geschlec1_1_, geschlecht2_.geschlecht_name as geschlec2_1_, familienst3_.familienstand_id as familien1_2_, familienst3_.familienstand_bezeichnung as familien2_2_, nationitem4_.nation_id as nation_id3_, nationitem4_.nation_name as nation_n2_3_, gueterstan5_.gueterstand_id as gueterst1_4_, gueterstan5_.gueterstand_bezeichnung as gueterst2_4_, rechtsform6_.rechtsform_id as rechtsfo1_5_, rechtsform6_.rechtsform_bezeichnung as rechtsfo2_5_, rechtsform6_.rechtsform_rechtsformkat_id as rechtsfo3_5_, rechtsform6_.rechtsform_kennzeichen_person as rechtsfo4_5_, rechtsform7_.rechtsformkat_id as rechtsfo1_6_, rechtsform7_.rechtsformkat_bezeichnung as rechtsfo2_6_ from kde_np natuerlich0_, kde_np_anrede anredeitem1_, kde_np_geschlecht geschlecht2_, kde_np_familienstand familienst3_, kde_geo_nationen nationitem4_, kde_np_gueterstand gueterstan5_, kde_rechtsformen rechtsform6_, kde_rechtsform_kategorien rechtsform7_ where natuerlich0_.np_id=? and natuerlich0_.np_anrede_id=anredeitem1_.anrede_id(+) and natuerlich0_.np_geschlecht_id=geschlecht2_.geschlecht_id(+) and natuerlich0_.np_familienstand_id=familienst3_.familienstand_id(+) and natuerlich0_.np_nation_id=nationitem4_.nation_id(+) and natuerlich0_.np_gueterstand_id=gueterstan5_.gueterstand_id(+) and natuerlich0_.np_rechtsform_id=rechtsform6_.rechtsform_id(+) and rechtsform6_.rechtsform_rechtsformkat_id=rechtsform7_.rechtsformkat_id(+)
2005-03-16 09:07:56,015 ERROR [main] hibernate.DBController (DBController.java:151) - net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: 1, of class: de.knowis.isfinancial.organisation.model.NatuerlichePerson
net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: 1, of class: de.knowis.isfinancial.organisation.model.NatuerlichePerson
at net.sf.hibernate.ObjectNotFoundException.throwIfNull(ObjectNotFoundException.java:24)


Name and version of the database you are using:
Oracle 9.x

The generated SQL (show_sql=true):
2005-03-16 09:07:29,250 DEBUG [main] hibernate.SQL (BatcherImpl.java:230) - insert into kde_np (np_name, np_vorname, np_geburtsdatum, np_sterbedatum, np_geburtsname, np_geburtsvorname, np_geburtsort, np_titel, np_namenszusatz, np_legitimation_art, np_legitimation_nummer, np_legitimation_behoerde, np_legitimation_datum, np_legitimation_gueltig_bis, np_anrede_id, np_geschlecht_id, np_familienstand_id, np_nation_id, np_gueterstand_id, np_rechtsform_id, np_anmerkungen, np_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2005-03-16 09:07:29,296 WARN [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:57) - SQL Error: 1400, SQLState: 23000
2005-03-16 09:07:29,296 ERROR [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:58) - ORA-01400: Einfügen von NULL in ("KNOWIS_WIVO"."KDE_NP"."NP_RECHTSFORM_ID") nicht möglich

2005-03-16 09:07:29,312 WARN [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:57) - SQL Error: 1400, SQLState: 23000
2005-03-16 09:07:29,312 ERROR [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:58) - ORA-01400: Einfügen von NULL in ("KNOWIS_WIVO"."KDE_NP"."NP_RECHTSFORM_ID") nicht möglich

2005-03-16 09:07:29,328 WARN [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:57) - SQL Error: 1400, SQLState: 23000
2005-03-16 09:07:29,328 ERROR [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:58) - ORA-01400: Einfügen von NULL in ("KNOWIS_WIVO"."KDE_NP"."NP_RECHTSFORM_ID") nicht möglich

2005-03-16 09:07:29,343 WARN [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:57) - SQL Error: 1400, SQLState: 23000
2005-03-16 09:07:29,359 ERROR [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:58) - ORA-01400: Einfügen von NULL in ("KNOWIS_WIVO"."KDE_NP"."NP_RECHTSFORM_ID") nicht möglich

2005-03-16 09:07:29,359 ERROR [main] impl.SessionImpl (SessionImpl.java:2400) - Could not synchronize database state with session
2005-03-16 09:07:29,359 ERROR [main] hibernate.DBController (DBController.java:315) - net.sf.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

now I correct my inputs, ssi tcould store it, but Id is now set to a seeming correct id


Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 6:02 am 
Regular
Regular

Joined: Mon Oct 06, 2003 7:17 am
Posts: 58
Location: Switzerland
After a rollback you have to close the session and after you can open a new session and save it again.

Reto


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 6:50 am 
Newbie

Joined: Wed Mar 16, 2005 5:15 am
Posts: 2
Reto wrote:
After a rollback you have to close the session and after you can open a new session and save it again.

Reto

Thank you for your answer.
But I believe, that the problem is, that Hibernate sets the Id in my class instance. So, if I save it again, by reopen a session, nothing will be better, because Hibernate believes to update the row (Id !=0), but the row isn't yet set in the db tabel. So JDBC throws an exception.

Do you have another idea?

Thanks,
Ralph


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 10:51 am 
Regular
Regular

Joined: Mon Oct 06, 2003 7:17 am
Posts: 58
Location: Switzerland
Hibernate does only rollback the database transaction and not the session instance. You could set the id to the old value or create a new instance and copy the values from the old instance to the new one (without the id value)

Reto


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 6:48 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
Here is a relevant thread (to which I am trying to unify many other threads on this topic):

Canonical "Can't Recover From Version Exception" Thread


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

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.