-->
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: Saving Children with Parent - Composite Key issue
PostPosted: Wed Oct 24, 2007 7:23 am 
Newbie

Joined: Wed Oct 24, 2007 4:00 am
Posts: 1
Hi

I have a problem with saving "parent" and "child" records in one operation. The child PK is a composite
based on the FK from the parent and a sequence number that I set manually. The ID of parent is not being
set by hibernate so a constraint error occurs when the child is saved. These are my mapping
files where AUDIT_EVENT is the parent table and AUDIT_EVENT_DETAILS is the child table.

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 16-Oct-2007 17:45:25 by Hibernate Tools 3.2.0.beta7 -->
<hibernate-mapping>
<class name="AuditEvent" table="AUDIT_EVENT">
<id name="auditEventId" type="java.lang.Long">
<column name="AUDIT_EVENT_ID" precision="22" scale="0" />
<generator class="sequence">
<param name="sequence">AuditEventSeq</param>
</generator>
</id>
<many-to-one name="functionType" class="FunctionType" fetch="select">
<column name="FUNCTION_TYPE_ID" precision="22" scale="0" not-null="true" />
</many-to-one>
<many-to-one name="function" class="Function" fetch="select">
<column name="FUNCTION_ID" precision="22" scale="0" not-null="true" />
</many-to-one>
<property name="auditEventDate" type="date">
<column name="AUDIT_EVENT_DATE" length="7" not-null="true" />
</property>>
<property name="userId" type="string">
<column name="USER_ID" length="128" />
</property>
<set name="auditEventDetailses" cascade="all" inverse="true">
<key>
<column name="AUDIT_EVENT_ID" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="AuditEventDetails" />
</set>
</class>
</hibernate-mapping>


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 16-Oct-2007 17:45:25 by Hibernate Tools 3.2.0.beta7 -->
<hibernate-mapping>
<class name="AuditEventDetails" table="AUDIT_EVENT_DETAILS">
<composite-id name="id" class="AuditEventDetailsId">
<key-property name="auditEventId" type="java.lang.Long">
<column name="AUDIT_EVENT_ID" precision="22" scale="0" />
</key-property>

<key-property name="auditEventDetailSeq" type="java.lang.Long">
<column name="AUDIT_EVENT_DETAIL_SEQ" precision="22" scale="0" />
</key-property>
</composite-id>
<many-to-one name="auditEvent" class="AuditEvent" update="false" insert="false" fetch="select">
<column name="AUDIT_EVENT_ID" precision="22" scale="0" not-null="true" />
</many-to-one>
<property name="auditEventCharName" type="string">
<column name="AUDIT_EVENT_CHAR_NAME" length="128" />
</property>
<property name="auditEventCharValue" type="string">
<column name="AUDIT_EVENT_CHAR_VALUE" length="128" />
</property>
</class>
</hibernate-mapping>

I see in the logs that the FK ID i.e. AUDIT_EVENT_ID is always set to 0.

I then set the mapping to use key-many-to-one


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 16-Oct-2007 17:45:25 by Hibernate Tools 3.2.0.beta7 -->
<hibernate-mapping>
<class name="AuditEventDetails" table="AUDIT_EVENT_DETAILS">
<composite-id name="id" class="AuditEventDetailsId">

<key-many-to-one name="auditEventId" class="AuditEvent" >
<column name="AUDIT_EVENT_ID" precision="22" scale="0" not-null="true" />
</key-many-to-one>

<key-property name="auditEventDetailSeq" type="java.lang.Long">
<column name="AUDIT_EVENT_DETAIL_SEQ" precision="22" scale="0" />
</key-property>

</composite-id>
<many-to-one name="auditEvent" class="AuditEvent" update="false" insert="false" fetch="select">
<column name="AUDIT_EVENT_ID" precision="22" scale="0" not-null="true" />
</many-to-one>
<property name="auditEventCharName" type="string">
<column name="AUDIT_EVENT_CHAR_NAME" length="128" />
</property>
<property name="auditEventCharValue" type="string">
<column name="AUDIT_EVENT_CHAR_VALUE" length="128" />
</property>
</class>
</hibernate-mapping>

This I got this error

org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of AuditEvent.auditEventId

Hibernate version 3.2.5 ; Any ideas?

Regards
S


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 01, 2008 10:35 am 
Beginner
Beginner

Joined: Tue Jan 08, 2008 2:15 pm
Posts: 22
I have the exact same problem. What have you done to fix yours?


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.