Hi have a problem with key-many-to-one. Please explain me if you know the solution.
My hbm files are: 1) <?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 package="com.dao.domainobjects"> <class name="com.dao.domainobjects.AuditInfo" table="AUDIT_INFO"> <id name="id" type="java.lang.Integer" column="ID"> <generator class="increment" />
</id> <property name="domain" type="java.lang.String" column="DOMAIN" length="100" /> <property name="applicationName" type="java.lang.String" column="APPLICATION_NAME" length="100" /> <property name="processName" type="java.lang.String" column="PROCESS_NAME" length="100" /> <property name="transactionID" type="java.lang.String" column="TRANSACTION_ID" length="100" /> <property name="instanceID" type="java.lang.String" column="INSTANCE_ID" length="100" /> <property name="time" type="timestamp" column="TIME" length="100" /> <property name="code" type="java.lang.String" column="CODE" length="100" /> <property name="message" type="java.lang.String" column="MESSAGE" length="4000" /> <property name="hostName" type="java.lang.String" column="HOST_NAME" length="100" /> <property name="userName" type="java.lang.String" column="USER_NAME" length="100" /> <property name="context" type="java.lang.String" column="CONTEXT" length="100" /> <property name="subContext" type="java.lang.String" column="SUB_CONTEXT" length="100" /> <set name="auditparamset" table="AUDIT_PARAM" cascade="all" inverse="true" lazy="true"> <key column="AUDIT_ID" /> <one-to-many class="com.dao.domainobjects.AuditParam"/> </set> </class> </hibernate-mapping>
2)<?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 package="com.dao.domainobjects"> <class name="com.dao.domainobjects.AuditParam" table="AUDIT_PARAM"> <composite-id> <!-- <key-property name="auditId" column="AUDIT_ID"/> --> <key-property name="name" type="java.lang.String" column="NAME"/> <key-many-to-one name="auditInfo" column="AUDIT_ID"/> </composite-id>
<property name="value"> <column name="VALUE" length="300" not-null="true" /> </property> </class> </hibernate-mapping>
when i have set the 2 values in the AuditParam. i am getting the following error.
Hibernate: select auditparam_.NAME, auditparam_.AUDIT_ID, auditparam_.VALUE as VALUE1_ from AUDIT_PARAM auditparam_ where auditparam_.NAME=? and auditparam_.AUDIT_ID=? Hibernate: select auditparam_.NAME, auditparam_.AUDIT_ID, auditparam_.VALUE as VALUE1_ from AUDIT_PARAM auditparam_ where auditparam_.NAME=? and auditparam_.AUDIT_ID=? Hibernate: insert into AUDIT_INFO (DOMAIN, APPLICATION_NAME, PROCESS_NAME, TRANSACTION_ID, INSTANCE_ID, TIME, CODE, MESSAGE, HOST_NAME, USER_NAME, CONTEXT, SUB_CONTEXT, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) Hibernate: insert into AUDIT_PARAM (VALUE, NAME, AUDIT_ID) values (?, ?, ?) Hibernate: insert into AUDIT_PARAM (VALUE, NAME, AUDIT_ID) values (?, ?, ?) org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:74) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:179) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136) 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:675) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:293) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86) at com.hcl.leaf.dao.impl.LeafDAOimpl.addAudit(LeafDAOimpl.java:28) at com.hcl.leaf.dao.domainobjects.Test.main(Test.java:48) Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("LEAF"."AUDIT_PARAM"."AUDIT_ID")
at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:458) at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:172) ... 9 more
When i have set the single value. i am able to save the single record in the DB. Please suggest where i have made the mistake.
Thanks, Naven.
|