-->
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: How to map a component object to be null if value is '-1'?
PostPosted: Tue Mar 08, 2011 11:36 am 
Regular
Regular

Joined: Tue Apr 10, 2007 10:02 am
Posts: 56
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?


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.