-->
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: Problem with subClass
PostPosted: Fri Nov 14, 2003 11:04 am 
Beginner
Beginner

Joined: Thu Oct 02, 2003 8:02 am
Posts: 45
I have a abstract class User with 2 subclasses Particulier and Entreprise define with the following mapping :

<class name="com.cfort.utilisateur.Utilisateur" table="utilisateur" discriminator-value="U">
<id name="identifiant" column="identifiant" type="string" length="20">
<generator class="assigned"/>
</id>
<discriminator column="type" type="character"/>
<property name="dateAbonnement" type="date"/>
<property name="datePaiement" type="date"/>
<property name="modeReglement">
<column name="modeReglement" sql-type="varchar(30)"/>
</property>
<property name="nbPoints" type="integer"/>
<subclass name="com.cfort.utilisateur.Particulier" discriminator-value="P">
<property name="nom" type="string" length="30"/>
<property name="prenom" type="string" length="30"/>
<property name="dateNaissance" type="date"/>
</subclass>
<subclass name="com.cfort.utilisateur.Entreprise" discriminator-value="U">
<property name="raisonSociale" type="string" length="60"/>
<property name="nbSalarie" type="integer"/>
<property name="numInsee" type="string" length="20"/>
</subclass>

</class>

When i retrieve a user, how can i test if it's a Particulier's instance or a Enterprise's instance in order to access the specificities of such an instance.
Can someone show me the piece of code .

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 14, 2003 11:16 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
If you are retrieving all Users try:

Code:
if (object instanceof com.cfort.utilisateur.Particulier) {
   // do something here with this object
} else if (object instanceof com.cfort.utilisateur.Entreprise) {
   // do something here with this object
} else {
    throw new IllegalStateException(
        "Unknown instance type" + (obj == null : "null" ? obj.getClass());
}


Q for the experts - would this work with proxied objects?


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.