Solution 1:If subjects, objects, and predicates are practically the same thing and you deal with them very similarly in your code, just add a "concept_type" field to your concept. In Java, declare an enum:
Code:
public class Concept {
public enum Type {
SUBJECT,
OBJECT,
PREDICATE;
}
// This is your database field
private String typeStr;
// Database field getters and setters are private so only Hibernate and this class can access them
private String getTypeStr() { return typeStr; }
private void setTypeStr(String t) { typeStr = t; }
// All other classes must use the enum to set and read the type value:
public Type getType() {
if (typeStr == null) { return null; }
return Concept.valueOf(typeStr);
}
public void setType(Type t) {
if (t == null) {
typeStr == null;
} else {
typeStr = t.toString();
}
}
}
Solution 2:I'm guessing your object, subject, and predicates have some similarities, but also significant differences. Depending on what you are doing with your concept object, you may want to have 3 different types of objects: object, subject, and predicate. If they have similar fields, name those fields exactly the same, then make a "Concept" interface that contains those fields and make your three classes implement that interface. If you need to get a set from the Triple object, you can have:
Code:
public Set<Concept> getConcepts() {
Set<Concept> ret = new HashSet<Concept>()
if (object != null) {
ret.add(object);
}
if (subject != null) {
ret.add(subject);
}
if (predicate != null) {
ret.add(predicate);
}
return ret;
}
You no longer need a triple_has_concept table. Rather:
Code:
triple
id
subject_id
object_id
predicate_id
You asked for other ideas and no-one else responded, so there are some ideas.