-->
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: DB2 Problem
PostPosted: Thu Sep 08, 2005 11:50 am 
Newbie

Joined: Thu Sep 01, 2005 12:28 pm
Posts: 9
I have a DB2 database which works as follows:

INSERT INTO T1 VALUES ('04.01.1998','WERT227','WERT327');
---------+---------+---------+---------+---------+---------+-----
DSNE615I NUMBER OF ROWS AFFECTED IS 1
DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 0
---------+---------+---------+---------+---------+---------+-----
COMMIT;
---------+---------+---------+---------+---------+---------+-----
DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 0
---------+---------+---------+---------+---------+---------+-----

UPDATE T1 SET T1DAT2 = 'QQ';
---------+---------+---------+---------+---------+---------+-----
DSNE615I NUMBER OF ROWS AFFECTED IS 1
DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 0
---------+---------+---------+---------+---------+---------+-----
DELETE FROM T1;
---------+---------+---------+---------+---------+---------+-----
DSNE615I NUMBER OF ROWS AFFECTED IS 1
DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 0


But when I try to update or delete with Hibernate comes the following Error:
org.hibernate.HibernateException: Unexpected row count: 0 expected: 1

This error comes just by update and delete, insert works very normally. Could it be that Hibernate is working with the SQLCODE and not the affected rows?
I tried using db2 java driver as well as connect through ODBC still nothing. Also I tried all of the dialects for DB2 still nothing.

Any help will be very appriciated :-)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 3:18 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
not sure if this is the cause...
but... make sure that you have use_sql_comments property in hibernate configuration set to false.

apparently that causes problems with db2


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 4:05 pm 
Newbie

Joined: Thu Sep 01, 2005 12:28 pm
Posts: 9
It is set to false. The only property set to true is show_sql


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 4:42 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
Could you post your mappings and code.

This may not be db2 specific problem.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 11:43 am 
Newbie

Joined: Thu Sep 01, 2005 12:28 pm
Posts: 9
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">COM.ibm.db2.jdbc.app.DB2Driver</property>
<property name="connection.url">jdbc:db2:Z0MVSDB1</property>
<property name="connection.username">username</property>
<property name="connection.password">pass</property>

<property name="show_sql">true</property>
<property name="use_sql_comments">false</property>
<property name="dialect">org.hibernate.dialect.DB2Dialect</property>

<mapping resource="D055Dienststelle.hbm.xml"/>

</session-factory>

</hibernate-configuration>


D055Dienststelle.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="de.itamtbw.v1207a3300.persistence.hibernate.D055Dienststelle" table="G120700A.D055_DIENSTSTELLE">

<id name="b055Dnr" column="`B055_DNR`"/>

<property name="b055Dstelle" column="`B055_DSTELLE`"/>

</class>
</hibernate-mapping>


D055Dienstelle.java
public class D055Dienststelle {
private String b055Dnr;
private String b055Dstelle;

public String getB055Dnr() {
if (this.b055Dnr != null) {
return this.b055Dnr.trim();
} else {
return "";
}
}

public String getB055Dstelle() {
if (this.b055Dstelle != null) {
return this.b055Dstelle.trim();
} else {
return "";
}
}

public void setB055Dnr(String b055Dnr) {
this.b055Dnr = b055Dnr;
}

public void setB055Dstelle(String b055Dstelle) {
this.b055Dstelle = b055Dstelle;
}
}


An update method:
public static void updateDienststelle() throws Exception {
Transaction tx = null;
try {
Session sess = HibernateUtil.currentSession();
tx = sess.beginTransaction();

D055Dienststelle b055Dienststelle = (D055Dienststelle) sess.get(
D055Dienststelle.class, "08020");
b055Dienststelle.setB055Dstelle("Test");

sess.update(b055Dienststelle);

tx.commit();
sess.flush();
} catch (HibernateException ex) {
if (tx != null)
tx.rollback();
log.error("SQL-Fehler gefunden : " + ex.getMessage());
BabsyFatalException bfEx = new BabsyFatalException();
bfEx.setMessageKey(MSGKEY_SQLERROR);
String args[] = { ex.getMessage() };
bfEx.setMessageArgs(args);
throw bfEx;
} finally {
HibernateUtil.closeSession();
}
}


A help class for using Hibernate:
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

private static Log log = LogFactory
.getLog(HibernateUtil.class);

private static final SessionFactory sessionFactory;

static {
try {
// Create the SessionFactory
sessionFactory = new Configuration().configure()
.buildSessionFactory();
} catch (Throwable ex) {
// Make sure the excpetion is logged, it might be swallowed
log.error("Initial SessionFactory creation failed.", ex);
throw new ExceptionInInitializerError(ex);
}
}

public static final ThreadLocal session = new ThreadLocal();

public static Session currentSession() {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}

public static void closeSession() {
Session s = (Session) session.get();
if (s != null) {
s.close();
}
session.set(null);
}
}



The Log:
16:37:41,035 INFO Environment:468 - Hibernate 3.1 beta 2
16:37:41,035 INFO Environment:481 - hibernate.properties not found
16:37:41,051 INFO Environment:514 - using CGLIB reflection optimizer
16:37:41,051 INFO Environment:544 - using JDK 1.4 java.sql.Timestamp
handling
16:37:41,176 INFO Configuration:1212 - configuring from resource:
/hibernate.cfg.xml
16:37:41,191 INFO Configuration:1180 - Configuration resource:
/hibernate.cfg.xml
16:37:42,066 INFO Configuration:457 - Reading mappings from resource: D055Dienststelle.hbm.xml
16:37:42,082 INFO HbmBinder:309 - Mapping class:
de.itamtbw.v1207a3300.persistence.hibernate.D055Dienststelle -> G120700A.D055_DIENSTSTELLE
16:37:42,129 INFO Configuration:1323 - Configured SessionFactory: null
16:37:42,129 INFO Configuration:960 - processing extends queue
16:37:42,129 INFO Configuration:964 - processing collection mappings
16:37:42,129 INFO Configuration:973 - processing association property
references
16:37:42,145 INFO Configuration:995 - processing foreign key constraints
16:37:43,066 INFO DriverManagerConnectionProvider:41 - Using Hibernate
built-in connection pool (not for production use
!)
16:37:43,082 INFO DriverManagerConnectionProvider:42 - Hibernate
connection pool size: 20
16:37:43,082 INFO DriverManagerConnectionProvider:45 - autocommit mode:
false
16:37:43,551 INFO DriverManagerConnectionProvider:80 - using driver:
COM.ibm.db2.jdbc.app.DB2Driver at URL: jdbc:db2:Z0
MVSDB1
16:37:43,566 INFO DriverManagerConnectionProvider:86 - connection
properties: {user=user, password=****}
16:37:44,332 INFO SettingsFactory:77 - RDBMS: DB2, version: 07.01.0001
16:37:44,332 INFO SettingsFactory:78 - JDBC driver: IBM DB2 JDBC 2.0 Type
2, version: 07.02.0000
16:37:44,379 INFO Dialect:100 - Using dialect:
org.hibernate.dialect.DB2Dialect
16:37:44,395 INFO TransactionFactoryFactory:31 - Using default transaction
strategy (direct JDBC transactions)
16:37:44,395 INFO TransactionManagerLookupFactory:33 - No
TransactionManagerLookup configured (in JTA environment, use
of read-write or transactional second-level cache is not recommended)
16:37:44,410 INFO SettingsFactory:125 - Automatic flush during
beforeCompletion(): disabled
16:37:44,410 INFO SettingsFactory:129 - Automatic session close at end of
transaction: disabled
16:37:44,410 INFO SettingsFactory:144 - Scrollable result sets: enabled
16:37:44,410 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): disabled
16:37:44,410 INFO SettingsFactory:160 - Connection release mode: null
16:37:44,426 INFO SettingsFactory:187 - Default batch fetch size: 1
16:37:44,426 INFO SettingsFactory:191 - Generate SQL with comments:
disabled
16:37:44,426 INFO SettingsFactory:195 - Order SQL updates by primary key:
disabled
16:37:44,426 INFO SettingsFactory:338 - Query translator:
org.hibernate.hql.ast.ASTQueryTranslatorFactory
16:37:44,441 INFO ASTQueryTranslatorFactory:21 - Using
ASTQueryTranslatorFactory
16:37:44,441 INFO SettingsFactory:203 - Query language substitutions: {}
16:37:44,441 INFO SettingsFactory:209 - Second-level cache: enabled
16:37:44,441 INFO SettingsFactory:213 - Query cache: disabled
16:37:44,441 INFO SettingsFactory:325 - Cache provider:
org.hibernate.cache.EhCacheProvider
16:37:44,457 INFO SettingsFactory:228 - Optimize cache for minimal puts:
disabled
16:37:44,457 INFO SettingsFactory:237 - Structured second-level cache
entries: disabled
16:37:44,473 INFO SettingsFactory:257 - Echoing all SQL to stdout
16:37:44,473 INFO SettingsFactory:264 - Statistics: disabled
16:37:44,473 INFO SettingsFactory:268 - Deleted entity synthetic
identifier rollback: disabled
16:37:44,488 INFO SettingsFactory:283 - Default entity-mode: POJO
16:37:44,566 INFO SessionFactoryImpl:157 - building session factory
16:37:44,598 WARN Configurator:126 - No configuration found. Configuring
ehcache from ehcache-failsafe.xml found in the
classpath:
file:/D:/Tomcat/work/Catalina/localhost/babsy/loader/ehcache-failsafe.xml
16:37:45,488 INFO SessionFactoryObjectFactory:82 - Not binding factory to
JNDI, no JNDI name configured
16:37:45,488 INFO SessionFactoryImpl:427 - Checking 0 named queries
Hibernate: select d055dienst0_."B055_DNR" as B1_11_0_,
d055dienst0_."B055_DSTELLE" as B2_11_0_ from G120700A.D055_DIENST
STELLE d055dienst0_ where d055dienst0_."B055_DNR"=?
Hibernate: update G120700A.D055_DIENSTSTELLE set "B055_DSTELLE"=? where
"B055_DNR"=?
16:37:46,020 ERROR AbstractFlushingEventListener:299 - Could not
synchronize database state with session
org.hibernate.HibernateException: Unexpected row count: 0 expected: 1
at
org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:33)
at
org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2187)
at
org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2103)
at
org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2357)
at
org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:84)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
at
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:29
6)
at
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:870)
at
org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:344)
at
org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at
de.itamtbw.v1207a3300.business.common.D055DienststelleCommon.updateDienststelle(D055DienststelleCommon.java:6
8)
at
de.itamtbw.v1207a3300.business.logic.BA003BusinessLogic.logicBa003ToBb001(BA003BusinessLogic.java:362)
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
de.itamtbw.v1207a3300.utils.FormUtilities.callBusinessLogic(FormUtilities.java:158)
at
de.itamtbw.v1207a3300.gui.actions.PBA003Action.execute(PBA003Action.java:105)
at
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:534)
16:37:46,160 ERROR D055DienststelleCommon:73 - SQL-Fehler gefunden :
Unexpected row count: 0 expected: 1


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.