You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Sylvain ~ <sy...@gmail.com> on 2004/11/11 07:18:55 UTC

Inheritance problems

Hi, I'm quite newbie to OJB, and I really need help.

I've got one base class "AbstractRoom" and two derived classes "Room"
and "Apartement", and I need to store them in one table named
"abstract_rooms".

The problem is that when I generate repository schema for the
database, it's like if the Apartement class is dropped (even if
Xdoclet process the source file), because it is not present in the
resulting repository file, thus absent of AbstractRoom extends.
Despite abstract_rooms table contains all columns from Rooms class,
there is no one from Apartement.
It seems that my class "Apartement" is not seen by XDoclet as a
persitence capable class, or simply "forget" my class and I wonder
what Am I doing wrong.

Any help would be appreciated.
Sylvain.

Relevant extract of Source files :

--- Apartement.java ---

/**
 * @ojb.class 	table="abstract_rooms"
 * 
 * @ojb.field	name="testField"
 * 				jdbc-type="INTEGER"
 */
public class Apartment extends AbstractRoom {
       
    
    public Apartment(){
        super();
        ojbConcreteClass = Apartment.class.getName();
        }
    
	public Apartment(Apartment apart){
	    super(apart);
	    ojbConcreteClass = Apartment.class.getName();
		}

    public Apartment(int number, float size){
        super(number,size);
        ojbConcreteClass = Apartment.class.getName();
        }

--- AbstractRoom.java ---

/**
 * @author Sylvain
 * 16:06:12
 * @ojb.class	generate-table-info="false"
 * 							
 *  -- doesn't seems to be taken in account event if I use
determine-extends="false"
 * @ojb.extent-class class-ref="kdms.core.Room"
 * @ojb.extent-class class-ref="kdms.core.Apartement"
 * 
 * --- Primary Key ---
 * @ojb.field 	name="abstractroom_id"
 * 				primarykey="true"
 *            	autoincrement="database"
 * 				jdbc-type="INTEGER" 
 **/

public class AbstractRoom implements StorableObject{
    
    /** the special attribute telling OJB the object's concrete type.
     *  NOTE: this attribute MUST be called ojbConcreteClass
     * @ojb.field 	length="50"
     */
    protected String ojbConcreteClass;
    
    /** Room/Apt n°
	 * @ojb.field name="number"
	 */
	protected int number;
    
    /** Room/Apt size
	 * @ojb.field name="size"
	 */
	protected float size;
	
    /**
     * Network Addresses Collection
     * @ojb.collection 	name="nAddresses"
     * 					element-class-ref="kdms.core.NetworkAddress"
     * 					foreignkey="abstractroom_id"
     * 					auto-update="true"
     * 					auto-retrieve="true"
     * 					auto-delete="false"	
    */ 
	protected NetworkAddressVector nAddresses;
}

--- Room.java ---

/**
 * @author Sylvain
 * 13:46:01
 * 
 * --- Class Storage Properties ---
 * 
 * @ojb.class 	table="abstract_rooms"
 *
 * 
 * --- Foreign Keys ---
 * 
 * @ojb.field 	name="apartment_id"
 * 				jdbc-type="INTEGER"
 *
 * --- Index ---
 * 
 * @ojb.index name="room_unique"
 *            unique="true"
 *            fields="number,apartment_id"
 */

public class Room extends AbstractRoom{    

    /** Student Capacity
	 * @ojb.field name="capacity"
	 */
	private int capacity;
    
	public Room(){
	    super();
	    ojbConcreteClass = Room.class.getName();
	    }
	
    public Room(int number, int capacity, float size){
        super(number,size);
        ojbConcreteClass = Room.class.getName();
        this.capacity = capacity;
        }
    
    public Room(Room r){
        super(r);
        ojbConcreteClass = Room.class.getName();
        this.capacity = r.capacity;
        }

(...)
}

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org