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.  [ 1 post ] 
Author Message
 Post subject: Obtain objects of subclasses from superclasses
PostPosted: Mon Sep 25, 2006 10:58 am 
Newbie

Joined: Thu Jun 22, 2006 7:19 am
Posts: 14
Hi. I am writing my first serious application with Hibernate. I am using Hibernate 3.2 and hibernate-annotations 3.2.0CR2. I have a bse class:



Code:
@MappedSuperclass
public class Base {

   // Variables estáticas

    private static Logger log = Logger.getLogger(Base.class);


    // Variables de instancia

    private int id;
    private String name;
    private String description;


    // Métodos de instancia

    protected Base() {
        log.debug("Creando nuevo objeto.");
    }

    @Id()
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

}


And two other classes, Computer and ComputerGroup, extending the Base class. What I want is to create a static method in the Base class so when i call:

Code:
Computer.get(1);


or

Code:
ComputerGroup.getAll();


returns the Computer object with identifier 1, or null if it does not exist; or all the ComputerGroup objects in the database without the need to write the implementation of the method in each child class, only write these methods in the Base class. I supose it should be written with generics, but i do not know how. I have tried differet ways without result.

Anybody know if is this possible and how to do it?

Thanks in advance.


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

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.