Hi,
My Hibernate Config file.
Code:
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.DB2400Dialect</property>
<property name="show_sql">true</property>
<property name="use_outer_join">false</property>
<property name="hibernate.connection.driver_class">com.ibm.as400.access.AS400JDBCDriver</property>
<property name="hibernate.connection.url">jdbc:as400://172.18.0.14</property>
<property name="hibernate.connection.username">dontest</property>
<property name="hibernate.connection.password">dontest</property>
<property name="hibernate.connection.pool_size">2</property>
<property name="default_schema">LWFILES900</property>
<property name="hibernate.cglib.use_reflection_optimizer">false</property>
<property name="hibernate.connection.autocommit">true</property>
<property name="hibernate.connection.isolation">1</property>
<property name="hibernate.format_sql">true</property>
<mapping resource="TestASMMST.hbm.xml" />
</session-factory>
</hibernate-configuration>
Mapping FileCode:
<hibernate-mapping auto-import="true" default-lazy="false">
<!-- Mapping of Question with table 'ASMMST' -->
<class name="Question" table="ASMMST" dynamic-update="true">
<id name="number" column="ASMQUN">
<generator class="identity"/>
</id>
<property name="type" column="ASMTYP"/>
<property name="question" column="ASMQUE"/>
<property name="clientSelfAssessment" column="ASMCSA"/>
<property name="required" column="ASMREQ"/>
<property name="applicableSex" column="ASMSEX"/>
<property name="minimumAge" column="ASMAGEMIN" type = "java.lang.Integer"/>
<property name="maximumAge" column="ASMAGEMAX" type = "java.lang.Integer"/>
<property name="prerequisiteQuestion" column="ASMPREQNM" type = "java.lang.Integer" />
<property name="prerequisiteAnswer" column="ASMPREQNA"/>
<property name="status" column="ASMSTS" type = "java.lang.Character" />
<property name="significantLifeEvent" column="ASMSLE" type = "java.lang.Character" />
<property name="strengthOrSupport" column="ASMSTR" type = "java.lang.Character" />
<property name="limitationToTreatment" column="ASMLTT" type = "java.lang.Character" />
<property name="relevantSymptom" column="ASMRES" type = "java.lang.Character" />
<property name="additionalOption1" column="ASMAD1" type = "java.lang.Character" />
<property name="additionalOption2" column="ASMAD2" type = "java.lang.Character" />
<property name="additionalOption3" column="ASMAD3" type = "java.lang.Character" />
<property name="additionalOption4" column="ASMAD4" type = "java.lang.Character" />
</class>
</hibernate-mapping>
Updation CodeCode:
Session session = HibernateSessionFactory.currentSession();
Question question = new Question();
question.setMinimumAge(11);
Transaction transaction = session.beginTransaction();
session.update(question);
session.flush();
transaction.commit();
session.close();
Stacktrace while Updating a row which existsCode:
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not update: [Question#0]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:2000)
at org.hibernate.persister.entity.BasicEntityPersister.updateOrInsert(BasicEntityPersister.java:1909)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:2149)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:75)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at TestASMMST.main(TestASMMST.java:49)
Caused by: java.sql.SQLException: [SQL7008] ASMMST in LWFILES900 not valid for operation.
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:650)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:621)
at com.ibm.as400.access.AS400JDBCStatement.commonExecute(AS400JDBCStatement.java:870)
at com.ibm.as400.access.AS400JDBCPreparedStatement.executeUpdate(AS400JDBCPreparedStatement.java:1138)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:1982)
... 10 more
Insertion CodeCode:
Session session = HibernateSessionFactory.currentSession();
Question question = new Question();
question.setNumber(9199);
question.setQuestion("Testing By Simhadri!!!!!!!!!!!!");
question.setApplicableSex('B');
question.setMinimumAge(11);
question.setMaximumAge(18);
question.setType("Y/N");
question.setClientSelfAssessment(true);
question.setRequired(true);
question.setStatus('A');
question.setSignificantLifeEvent('Y');
question.setLimitationToTreatment('N');
question.setStrengthOrSupport('Y');
question.setRelevantSymptom('N');
question.setAdditionalOption1('Y');
question.setAdditionalOption2('N');
question.setAdditionalOption1('N');
question.setAdditionalOption2('Y');
System.out.println("Question NO: " + question.getNumber());
session.save(question);
Stacktrace while insertingCode:
Exception in thread "main" org.hibernate.exception.ConstraintViolationException: could not insert: [Question]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:63)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1777)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2178)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:34)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:240)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:95)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:476)
at TestASMMST.main(TestASMMST.java:35)
Caused by: java.sql.SQLException: [SQL0803] Duplicate key value specified.
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:650)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:621)
at com.ibm.as400.access.AS400JDBCStatement.commonExecute(AS400JDBCStatement.java:870)
at com.ibm.as400.access.AS400JDBCPreparedStatement.executeUpdate(AS400JDBCPreparedStatement.java:1138)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1759
Selection/Loading of a specfic row is working fine but
Regarding UpdationI am executing an UPDATE statement using Hibernate3 on a table EMPDEPT in DB2/400 on LIBRARY900 library. I am using jt400.jar as a driver api to connect to the database using Java and Hibernate.
I was getting a SQLexpection stating
java.sql.SQLException: [SQL7008] EMPDEPT in LIBRARY900 not valid for operation.
If I am executing the same update externally using sql client, it is working fine.
The Table on which I am updating is not journled.
I found somewhere on net stating this happens due to Update Safe Mode variable is set/default to 1, and update fails if more than one record is updated in the same transaction.
Does Hibernate updates more than one row at a time even it is expected to update only one row as i was updating the row using the primary key in the where clause.
As I am updating only one record, I was not able to figure out what other issues are causing this exception.
Does it has anything to do with journling and other stuff or is it the problem of Hibernate3 which I am not sure of.
Regarding InsertionI am trying to insert a new row into a table, even the row does not exist, it is giving me an exception stating, Constraint Violation error the Duplicate Row.
I am not sure where I am going wrong.
Appreciate any help!!
Thanks & Regards,
Code:
[quote][/quote]
Code: