I face an issue with Hibernate mapping file I have one to many and many to one. Please read below:-
Error in Stack Trace:
18:19:17,933 WARN JDBCExceptionReporter:233 - SQL Error: 1400, SQLState: 23000 18:19:17,934 ERROR JDBCExceptionReporter:234 - ORA-01400: cannot insert NULL into ("PCSMSCNL"."PCS_ORDER_HEADER"."USER_KEY_CREATED")
Tables and HBM
Parent Table has composite primary key - Table Name - PCS_USER
USER_KEY (PK) DIVISION_KEY (PK)
PcsUser.hbm.xml
<class name="com.systemax.entities.PcsUser" table="PCS_USER"> <composite-id name="id" class="com.systemax.entities.PcsUserId"> <key-property name="userKey" type="java.lang.Long"> <column name="USER_KEY" precision="10" scale="0" /> </key-property> <key-property name="divisionKey" type="java.lang.Short"> <column name="DIVISION_KEY" precision="4" scale="0" /> </key-property> </composite-id>
<set name="pcsOrderHeadersForUserKeyCreated" table="PCS_ORDER_HEADER" inverse="true" lazy="true" fetch="select" > <key> <column name="USER_KEY_CREATED" precision="10" scale="0" not-null="false" /> <column name="DIVISION_KEY" precision="4" scale="0" not-null="false"/> </key> <one-to-many class="com.systemax.entities.PcsOrderHeader" /> </set> </class name>
Child Table (PCS_ORDER_HEADER) has foreign key constraints in which of them is a primary key (DIVISION_KEY) and the other one (USER_KEY_CREATED) is not.
Table - PCS_ORDER_HEADER
DIVISION_KEY (PK) NOT and it references to Parent Table PCS_USER column DIVISION_KEY ORDER_KEY (PK) USER_KEY_CREATED (NOT NULL) and it references to Parent Table PCS_USER column USER_KEY
PCSOrderHeader.hbm.xml
<class name="com.systemax.entities.PcsOrderHeader" table="PCS_ORDER_HEADER"> <composite-id name="id" class="com.systemax.entities.PcsOrderHeaderId"> <key-property name="orderKey" type="long"> <column name="ORDER_KEY" precision="12" scale="0" /> </key-property> <key-property name="divisionKey" type="short"> <column name="DIVISION_KEY" precision="4" scale="0" /> </key-property> </composite-id> </class name>
<many-to-one name="pcsUserByUserKeyCreated" class="com.systemax.entities.PcsUser" update="false" insert="false" fetch="select"> <column name="USER_KEY_CREATED" precision="10" scale="0" not-null="true" /> <column name="DIVISION_KEY" precision="4" scale="0" not-null="true" /> </many-to-one>
I am not sure what's wrong in the above mapping. Also My project has xml tags, no annotations. Please provide the solution in xml tag if you figure out the issue.
Thanks, Sathish.
|