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
|