I'm trying to create hibernate mappings for a hierarchy, as follows...
The schema...
Code:
CREATE TABLE `organization` (
  `OrgIntID` int(11) NOT NULL AUTO_INCREMENT,
  `OrgTitle` varchar(50) DEFAULT NULL,
  `OrgDesc` text,
  PRIMARY KEY (`OrgIntID`),
  UNIQUE KEY `OrgTitle` (`OrgTitle`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=latin1;
CREATE TABLE `org_hierarchy` (
  `OrgHierID` int(11) NOT NULL AUTO_INCREMENT,
  `ParentOrgIntID` int(11) NOT NULL DEFAULT '-1',
  `ChildOrgIntID` int(11) NOT NULL,
  `OrgHierDisplayOrder` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`OrgHierID`),
  KEY `ChildOrgIntID` (`ChildOrgIntID`),
  CONSTRAINT `fk_org_hierarchy_organization` FOREIGN KEY (`ChildOrgIntID`) REFERENCES `organization` (`OrgIntID`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=latin1;
The objects...
Code:
public class Organization {
   private int fID;
   private String fTitle;
   private String fDesc;
   ...
   ...   
}
public class OrganizationHierNode {
   private Organization fParent;   // should be null if the matching field value is '-1'
   private Organization fChild;
   ...
}
The hierarchy has been set up this way to allow an organization to appear in multiple locations within the hierarchy.  All top level nodes in this hierarchy have a 'ParentOrgIntID' setting of '-1'.   The problem comes, how do I translate this into a hibernate mapping?  The 'OrganizationHierNode' mapping would require something that sets the 'fParent' property to null if the related 'ParentOrgIntID' is '-1'.  Any ideas?