-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate Foreign Key Constraint Issue
PostPosted: Tue Aug 11, 2015 2:48 pm 
Newbie

Joined: Tue Aug 11, 2015 2:26 pm
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.