File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes issue that should be really simple Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "issue that should be really simple" Watch "issue that should be really simple" New topic
Author

issue that should be really simple

Andy Mel
Greenhorn

Joined: Jul 13, 2006
Posts: 3
I've got a performance object and within it a collection of deliverables (as a set). On initial creation everything works wonderfully. However when I update or remove an item from the collection or ad a new object to it as an update I get NULL insert errors. Using Hibernate I'm not updating the individual items in the collection I'm updating the "parent" object and would assume that it could tell what within it needs an update and what needs an insert. There are performanceID and deliverableID (both Longs) within the Deliverable objects, do they need to be set to something specific for this to function (or will 0 or null work?)

the following is the error that I'm currently getting when simply updating the current deliverables (everything has non-null id's)...

**********************************************************

SystemOut O Hibernate: update tblPerformance set ProjectID=?, MonthSubmitted=?, YearSubmitted=?, Draft=? where PerformanceID=?
[7/13/06 11:39:06:501 EDT] 47ff603 SystemOut O Hibernate: update tblDeliverable set PerformanceID=?, Description=?, Status=?, Comments=? where DeliverableID=?
[7/13/06 11:39:06:501 EDT] 47ff603 SystemOut O Hibernate: update tblDeliverable set PerformanceID=?, Description=?, Status=?, Comments=? where DeliverableID=?
[7/13/06 11:39:06:501 EDT] 47ff603 SystemOut O Hibernate: update tblDeliverable set PerformanceID=?, Description=?, Status=?, Comments=? where DeliverableID=?
[7/13/06 11:39:06:501 EDT] 47ff603 SystemOut O Hibernate: update tblDeliverable set PerformanceID=?, Description=?, Status=?, Comments=? where DeliverableID=?
[7/13/06 11:39:06:511 EDT] 47ff603 SystemOut O Hibernate: update tblDeliverable set PerformanceID=null where PerformanceID=?
[7/13/06 11:39:06:531 EDT] 47ff603 JDBCException W net.sf.hibernate.util.JDBCExceptionReporter SQL Error: 1407, SQLState: 72000
[7/13/06 11:39:06:541 EDT] 47ff603 JDBCException E net.sf.hibernate.util.JDBCExceptionReporter ORA-01407: cannot update ("BIOTECH_OWNER"."TBLDELIVERABLE"."PERFORMANCEID") to NULL

***************************************************

there are 4 deliverables associated with this particular performance report and they seem to be updated appropriately but I don't know where the last "update tblDeliverable set PerformanceID=null where PerformanceID=?" is coming from

the following are the two xml files

<hibernate-mapping>
<class name="bgtd.biotech.forms.PerformanceForm" table="tblPerformance">
<id name="performanceID" column="PerformanceID" type="long">
<generator class="sequence">
<param name="sequence">SEQPERFORMANCE</param>
</generator>
</id>
<property name="projectID" column="ProjectID" type="long"/>
<property name="statusMonth" column="MonthSubmitted" type="string"/>
<property name="statusYear" column="YearSubmitted" type="string"/>
<property name="draft" column="Draft" type="string"/>
<set name="deliverableSet" cascade="all-delete-orphan">
<key column="PerformanceID" not-null="true"/>
<one-to-many class="bgtd.biotech.forms.DeliverableForm"/>
</set>
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="bgtd.biotech.forms.DeliverableForm" table="tblDeliverable">
<id name="deliverableID" column="DeliverableID" type="long">
<generator class="sequence">
<param name="sequence">SEQDELIVERABLE</param>
</generator>
</id>
<property name="performanceID" column="PerformanceID" type="long"/>
<property name="description" column="Description" type="string"/>
<property name="status" column="Status" type="string"/>
<property name="comments" column="Comments" type="string"/>

</class>
</hibernate-mapping>


any thoughts would be appreciated...

thanks
Andy Mel
Greenhorn

Joined: Jul 13, 2006
Posts: 3
anyone?
Andy Mel
Greenhorn

Joined: Jul 13, 2006
Posts: 3
Thanks for the help there boys and girls... I was fighting the urge to try it out but with a profound lack of response I figured I might as well give it a go... easily one of the most idiotic mechanisms that I have ever encountered is the need to have a parent object as a property of the child object of a collection to get it working properly... so astoundingly non-object oriented it's not funny... oh well... for those of you encountering a similar issue in the parent xml declaration use a one-to-many relationship with cascade="all-delete-orphan" inverse="true" and a many-to-one relationship in the child and yes you will need to have the parent object as a property of the child (which will undoubtedly contain references to all the other children, which will contain references to their parent... etc.)... wow...
Jerry You
Greenhorn

Joined: Dec 09, 2005
Posts: 6
Hey, Andy,

I had similar problem just yesterday!
In our case, we were mapping 2 tables with "unidirectional" one-to-many association on foreign key. Based
on the Hibernate reference document, quote from 7.2.3

"A unidirectional one-to-many association on a foreign key is a very unusual case,
and is not really recommended." Looks like Hibernate really doesn't like this type of association
or database design - for some reason, Hibernate will issue "update to set to null" and this
will fail if you define the foreign key column in the child table to be "not null"

Hmm...I am not convinced it is "very unusual"....and there is nothing wrong to define the
foreign key column to be NOT NULL based on our business logic....

Anyway, the mapping files in our approach are very like those in the reference doc:

in the parent class mapping file, have "not-null"="true" in the key column
and remove the defination of the foreign key property from the child mapping file (otherwise we
had duplicate mapping error)

JY
 
 
subject: issue that should be really simple
 
Similar Threads
Why update statement issued in cascade = "save-update"
Hibernate Issue
JOIN syntax for HQL . Need help!
ORA-00001: unique constraint exception
many-to-many Not this saving, please help me