Announcement Announcement Module
Collapse
No announcement yet.
Hibernate: optional one-to-one mapping Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate: optional one-to-one mapping

    In my design I have two entities...

    Code:
    public class BuildingDesign { 
       .... 
       private int fID; 
       private String fTitle; 
       .... 
    } 
    
    public class BuildingDesignLock { 
       ... 
       private int fLockID; 
       private int fBuildingDesignID; 
       private String fUserID; 
       ... 
    } 
    
    CREATE TABLE `building_design` ( 
      `BuildingDesignID' int(11) NOT NULL auto_increment, 
      `BuildingDesignTitle` varchar(50) NOT NULL, 
      PRIMARY KEY  (`BuildingDesignID`), 
    ) 
    
    CREATE TABLE `building_design_lock` ( 
      `LockID' int(11) NOT NULL auto_increment, 
      `BuildingDesignID' int(11) NOT NULL, 
      `LockUserID` varchar(50) NOT NULL, 
      PRIMARY KEY  (`LockID`), 
      UNIQUE KEY `BuildingDesignID (`BuildingDesignID`))
    A 'building design' can be created independent of its related lock entity. The 'lock' entity is optional and used to hold the name of a user that has placed a write lock over a building design entity.

    There is a 1 to 1/0 link (i.e. optional one-to-one) link from BuildingDesign to BuildingDesignLock.

    I want to extract a list of the building designs with their lock status. For this I've created a descendant class like...

    Code:
    public class BuildingDesignInfo extends BuildingDesign { 
       .... 
       private BuildingDesingLock fLock; 
       .... 
    }
    I want to create a Hibernate mapping for this 'BuildingDesignInfo' class, but I can't find an example of a one-to-one mapping where the link is a foreign key in the second table.

    Can this be done?

  • #2
    Is the example in the reference manual the same thing?
    http://www.hibernate.org/hib_docs/v3...irectional-121

    Comment

    Working...
    X