-->
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.  [ 2 posts ] 
Author Message
 Post subject: Using discriminator on base class with no subclasses
PostPosted: Wed Sep 14, 2005 2:43 pm 
Newbie

Joined: Thu Jun 30, 2005 10:35 am
Posts: 13
Hi, I have a quick question that I hope somebody can help me with...

I have a table in my DB called AGREEMENT and there are 2 different objects types that get stored in this table. The way to tell which type of object it is, is by a discriminator column called DISC. I only ever need to deal with one of these objects, so in my mapping file I want to add a discriminator so that any other classes that are mapped to this one will always ONLY instantiate those rows that contain a specific discriminator value.

This is the mapping file that I set up:

<class name="agreement"
table="AGREEMENT"
discriminator-value="AGR">

<id name="id" column="AGREEMENT_ID">
<generator class="native"/>
</id>

<discriminator column="DISC" type="string"/>

....<property>....

</class>

So I want any other class that has a reference to this one, to only instantiate the rows that have "AGR" in the DISC column. I know I could do this with sql or a where clause, but the problem is that I need to be able to also write this value to the DISC column when I create and insert new rows, so the value must be mutable.

Anybody know the right way to do this? Using the mapping above, I still get every row loaded, irrelevant of what the discriminator is.

Thanks alot for any help!

(By the way, I'm not even sure if using a discriminator element is the correct way to do this since I have no subclasses)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 4:21 am 
Newbie

Joined: Thu Jan 08, 2004 5:11 am
Posts: 4
Location: France
you could use an interface and/or a super class (abstract or concrete), depending on the similarity between your 2 classes)

Code:
   <class name="IAgreement" table="AGREEMENT" discriminator-value="A">
        <id name="id" column="AGREEMENT_ID">
                <generator class="native"/>
        </id>
        <discriminator column="DISC" type="string"/>
        <subclass name="YourFirstAgreementClass" discriminator-value="AGR">
                <property .... />
        </subclass>
        <subclass name="YourOtherAgreementClass" discriminator-value="otherDiscrimnatorValue"/>
                <property .... />
        </subclass>
    </class>


just make your two classes implement the IAgreement interface or Agreement super-class


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.