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.  [ 2 posts ] 
Author Message
 Post subject: how can hibernate connect as400/db2
PostPosted: Tue Aug 24, 2010 8:59 pm 
Newbie

Joined: Mon Aug 23, 2010 8:16 pm
Posts: 3
if I use the Hibernate,how can the hibernate connect the as400/db2
could you give me a sample.thanks
I try to use the hibernate to connct the as400/db2
but when I save the data into as400/db2
,it always have exception.but i can check up the data from the as400/db2
by hibernate. thanks
-------------------------------------
Session session = sf.getCurrentSession();
Pwk2870 p1 = new Pwk2870();
Pwk2870Id pid = new Pwk2870Id();
short s1 = 70;
pid.setMmcono(s1);
pid.setMmitno("B");
pid.setMmmabu(true);
pid.setMmstat("A");
pid.setXxtest("XX");
p1.setId(pid);
session.beginTransaction();
session.save(p1);
session.getTransaction().commit();

-----------------------
org.hibernate.exception.GenericJDBCException: could not insert: [com.model.Pwk2870]
at org.hibernate.exception.SQLStateConverter.handledN onSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert( SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.conver t(JDBCExceptionHelper.java:66)
at org.hibernate.persister.entity.AbstractEntityPersi ster.insert(AbstractEntityPersister.java:2285)
at org.hibernate.persister.entity.AbstractEntityPersi ster.insert(AbstractEntityPersister.java:2678)
at org.hibernate.action.EntityInsertAction.execute(En tityInsertAction.java:79)
at org.hibernate.engine.ActionQueue.execute(ActionQue ue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListe ner.performExecutions(AbstractFlushingEventListene r.java:321)
at org.hibernate.event.def.DefaultFlushEventListener. onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.j ava:1028)
at org.hibernate.impl.SessionImpl.managedFlush(Sessio nImpl.java:366)
at org.hibernate.transaction.JDBCTransaction.commit(J DBCTransaction.java:137)
at com.test.HibernateTest.saveByObject(HibernateTest. java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runRefle ctiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExpl osively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod .evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgn ored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner. java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRu nner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentR unner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRu nner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRu nner.java:184)
at org.junit.internal.runners.statements.RunBefores.e valuate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.ev aluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.ja va:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:197)
Caused by: java.sql.SQLException: [SQL7008] PWK2870 in NCJPGM not valid for operation.
at com.ibm.as400.access.JDError.throwSQLException(JDE rror.java:687)
at com.ibm.as400.access.JDError.throwSQLException(JDE rror.java:653)
at com.ibm.as400.access.AS400JDBCStatement.commonExec ute(AS400JDBCStatement.java:920)
at com.ibm.as400.access.AS400JDBCPreparedStatement.ex ecuteUpdate(AS400JDBCPreparedStatement.java:1401)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(N onBatchingBatcher.java:46)
at org.hibernate.persister.entity.AbstractEntityPersi ster.insert(AbstractEntityPersister.java:2265)
... 36 more
--------------------------------
<session-factory name="ss">
<property name="hibernate.dialect">org.hibernate.dialect.DB2 400Dialect</property>
<property name="hibernate.connection.driver_class">com.ibm.a s400.access.AS400JDBCDriver</property>
<property name="hibernate.connection.url">jdbc:as400://****</property>
<property name="hibernate.connection.username">****</property>
<property name="hibernate.connection.password">****</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="com/model/Pwk2870.hbm.xml"/>
</session-factory>

---------------------------------this is mapping-------------------
<hibernate-mapping>
<class name="com.model.Pwk2870" table="PWK2870" schema="NCJPGM" catalog="S6513EF0">
<comment>NCDD LUO SAN TEST</comment>
<composite-id name="id" class="com.model.Pwk2870Id">
<key-property name="mmcono" type="short">
<column name="MMCONO" precision="3" scale="0" />
</key-property>
<key-property name="mmstat" type="string">
<column name="MMSTAT" length="2" />
</key-property>
<key-property name="xxtest" type="string">
<column name="XXTEST" length="5" />
</key-property>
<key-property name="mmitno" type="string">
<column name="MMITNO" length="15" />
</key-property>
<key-property name="mmmabu" type="boolean">
<column name="MMMABU" precision="1" scale="0" />
</key-property>
</composite-id>
</class>
</hibernate-mapping


Top
 Profile  
 
 Post subject: Re: how can hibernate connect as400/db2
PostPosted: Fri Nov 12, 2010 11:27 am 
Newbie

Joined: Fri Nov 12, 2010 10:56 am
Posts: 2
wrong dialect


put "org.hibernate.dialect.DB2400Dialect" and set the jt400 on class path.There should be no space in the DB2400Dialect.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.