Hello,
I've got what I believe to be a tricky hibernate mapping problem. I'd like to use hibernate annotations to do the following.
I have two(or more) classes, a person, and a game. They each will have an array of comments associated with them. Here comment is also an object and contains a string, the locale/language the comment is in, the date it was left etc.
What I'd like is for comments for people to be stored in a separate table from comments for games. My reasoning here is that it should yield more efficient lookups of comments, and may let me partition the database as we scale.
I can see how to do this if I have two separate comment classes one to be used by the person class, and another to be used by the game class. This would look as follows in rough pseudo code:
@Entity
public class person {
@OneToMany(cascade = ALL)
public Set<PersonComment> comments = new HashSet<PersonComment>();
}
@Entity
public class game {
@OneToMany(cascade = ALL)
public Set<GameComment> comments = new HashSet<GameComment>();
}
@Entity
@Table(name = "person_comments")
public class PersonComment {
...
}
@Entity
@Table(name = "person_comments")
public class GameComment {
...
}
The problem is that the two comment classes are identical, I just want to put them in two different tables, and the above is one (annoying/poor) way of doing that.
One strategy is to use a comment class as a super class of PersonComment and GameComment... which would let me share the class, but then I still need to have the PersonComment class and the GameComment class just so I can tell hibernate to store them in separate tables.
Is there a better way to do what I want?
I'm using [b]Hibernate version:[/b] 3.2.
Thanks in advance for any help.
~C
|