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.