-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to Map an Abstract Class?
PostPosted: Wed Oct 06, 2004 4:48 pm 
Newbie

Joined: Mon Aug 30, 2004 5:15 pm
Posts: 13
I have a situation where I want to map an abstract class, but I have no clue how to do that. My situation is that I have a Salesperson field. I want to make this Salesperson abstract because there will be several different types of salespeople. One type will be company Employees. These will be pulled from an LDAP directory. The other type is Contractors and that will be stored in the database.

Code:
abstract Salesperson {}

Employee extends Salesperson {
// retreived from LDAP
}

Contractor extends Salesperson {
// stored in database
}


How can I map this? I have read the documentation section on Inheritance, but it was above my programming knowledge.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 06, 2004 5:02 pm 
Newbie

Joined: Mon Aug 30, 2004 5:15 pm
Posts: 13
One more thing to clarify. The Salesperson class is a field of another class.

Code:
public class Item {
   Salesperson thisSalesperson;

}


Top
 Profile  
 
 Post subject: mapping abstract classes with concrete subclasses
PostPosted: Thu Oct 07, 2004 4:44 pm 
Newbie

Joined: Fri Sep 10, 2004 10:21 am
Posts: 7
I've tried the following with some level of success, but I'm a 'rookie' on hibernate mapping and have not had any hibernate guru critique my approach.

With that said, I have an abstract class and several concrete classes that extend this abstract class. Here's the java classes
Code:
public class abstract Employee {
   private int id;
   private string name;
   private string employeeName;

   public get.../set...
}

public class Programmer extends Employee {
}

public class SalesPerson extends Employee {
   private BigDecimal commission;

   public BigDecimal getCommission();
   public void setCommission(BigDecimal comm) { ... }
}

Here's my mapping file using your example classes...

Code:
  <class name="Employee" table="employees"  discriminator-value="employee" >

    <id name="id" column="id">
        <generator class="{your choice here}"/>
    </id>

    <!-- descriminator (must precede properties) -->
    <discriminator column="employee_type" type="string" />

    <property name="name" column="employee_name" type="string" length="32" not-null="true" access="field"/>
    <property name="employeeNumber" column="employee_number" type="string" length="32" not-null="true" access="field"/>


    <!-- programmer -->
    <subclass name="Programmer"
        discriminator-value="programmer">
    </subclass>

    <!-- Sales person -->
    <subclass name="SalesPerson"
        discriminator-value="sales">
        <property name="commission" column="commission" type="big_decimal" access="field" />
    </subclass>

   ...



Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 07, 2004 5:16 pm 
Newbie

Joined: Mon Aug 30, 2004 5:15 pm
Posts: 13
I just found an answer on a different post.

use the following in your mapping file:
Code:
<meta attribute="scope-class">public abstract</meta>


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