-->
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.  [ 5 posts ] 
Author Message
 Post subject: Subclass that extends the base class without discriminator?
PostPosted: Mon Jun 06, 2005 9:47 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
I'm hoping someone can help me out with this:

I've got a base class which contains the "lite" version of data and then a subclass that provides the additional detail. I want both classes to use the same table and am not sure if/why I need a discriminator.

Eg.
Code:
public class CustomerBase
{
    public int      ID;
    public string Name;
}

public class CustomerDetail : CustomerBase
{
    public string Address1;
    public string Address2;
    public string Suburb;

    //Etc...
}


I've set up a sample mapping like this:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="Types.CustomerBase, MyAssembly" table="Customers">
      <id name="ID" column="CustomerID">
         <generator class="native" />
      </id>
      <property name="Name" column="Name" />
      <subclass name="Types.CustomerDetail, MyAssembly" extends="Types.CustomerBase, MyAssembly">
         <property name="Address1" column="Address1" />
                        <property name="Address1" column="Address1" />
                        <property name="Suburb" column="Suburb" />
      </subclass>
   </class>
</hibernate-mapping>


...but it tells me that I need a discriminator. In effect, the base class is really just a stripped down version of the subclass (required for minimizing the amount of data being transferred over the wire in a high traffic web service) and it's going to be the only type in the table - is a discriminator really necessary?

Hope someone can clarify this for me...

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 11:39 am 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
I may be off base on this, but couldn't you use proxies to acheive the functionality you desire?

-Marc


Top
 Profile  
 
 Post subject: yes, the discriminator is required
PostPosted: Tue Jun 07, 2005 2:08 pm 
Regular
Regular

Joined: Tue May 24, 2005 12:55 pm
Posts: 56
I've tried to do the same thing and have found no way of doing it in the 2.0.* or 2.1 Hibernate docs. It appears to be meant as a way to subset data based on "type" columns. I'm not sure about proxies, nothing in the nhibernate docs, though there is a reference to "see Proxies for Lazy Initialization".


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 10:57 am 
Regular
Regular

Joined: Tue May 31, 2005 3:18 pm
Posts: 117
Location: Houston
the way to accomplish this is just to make 2 mapping files, as if they were different classes .. (well... they are)

Make sure and REPEAT the properties from customerbase into customerdetail.

Then you won't need a discriminator.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 12:14 pm 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
Thanks guys,

I guess I missed seeing your responses on this until now!

subdigital - I'll give your suggestion a try.

Thanks for your help.

Cheers,

Symon.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

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.