Nik, I've got a lot of these. I created tables in my DB (as it's easier to modify that than change my code, recompile, re-deploy, etc.) which all follow the same structure:
ID, Description
Some are:
ID, Description, Full Description (If they need a full length description.) But let's leave that alone for now. :P
What I did, was create an abstract Java Bean that has two properties called ID (long) and Description (String). I extend this for each of the tables that I have. Like this:
Code:
public abstract class TableReference {
private long id;
private String description;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public TableReference() {
super();
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
And here's a table that extends it...
Code:
public class PropertyType extends TableReference {
}
Then, for a nice and simple Hibernate mapping:
Code:
<class name="PropertyType" table="PropertyType">
<id name="id" column="ID" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="description" column="Description" not-null="true"/>
</class>
What you can do, is have some object, that has a Collection of these types. And hey presto, you have something that you can maintain in the database, and easily read into your system via a Hibernate query, like this:
Code:
Query q = session.createQuery("select c from " +
yourObject.class.getName() + " as c");
List listResult = q.list();
for (int i=0; i < listResult.size();i++) {
YourObject yourObject = (YourObject) listResult.get(i);
// Process as needed.
}
...
I hope that's what you're asking...otherwise I just cut 'n pasted and typed a whole lot of nothing. :P
-G