-->
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: Discriminator in separate object
PostPosted: Tue May 13, 2008 11:42 am 
Newbie

Joined: Fri May 09, 2008 10:29 am
Posts: 4
Hibernate version: 2.0

In my db schema there is a concept of a base table and an override table that is one-to-many. That is each override table may override properties of the base table. My domain model has an separate object for each table, where the override object contains a reference to the base table and override properties are proxied via the base object. In addition the override object is part of a polymorphic structure. Here is a sample:

Code:
public class BaseObject
{
   private string _one;
   public virtual string One
   {
      get {return _one;}
      set {_one = value;}
   }

   private int _categoryID;
   public virtual string CategoryID
   {
      get {return _categoryID;}
      set {_categoryID= value;}
   }
}

public class OverrideObject
{
   private BaseObject _base;
   public virtual BaseObject Base
   {
      get {return _base
      set {_base = value;}
   }

   private string _one;
   public virtual string One
   {
      get
      {
               if (string.IsNullOrEmpty (_one))
                  return Base.One;
               return _one;
      }
      set {_one = value;}
   }

   //for persisting
   public virtual string P_One
   {
      get {return _one;}
      set {_one = value;}
   }
}

public class OverrideSubClass:OverrideObject
{
   private string _two;
   public virtual string Two
   {
      get {return _two;}
      set {_two= value;}
   }
}


Here is the mapping for the override:
Code:
  <class name="OverrideObject" table="OverrideTable">
...
   <!-- here is where I want to create a formula to call Base.CategoryID -->
  <discriminator column="CategoryID"  />
  <property column="One" name="P_One" type="String"/>

  <many-to-one name="Base" class="BaseObject" column="BaseID"/>

  <subclass name="OverrideSubClass" discriminator-value="1" >
     <property column="Two" name="Two" type="string"/>

  </subclass>


What I would like to do is alias the many-to-one object 'Base' and call it in the discriminator. I'd rather not place SQL in the formula to join on the table, because the join is already happening in the many-to-one association. Any thoughts?


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.