-->
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.  [ 2 posts ] 
Author Message
 Post subject: Tricky Hibernate Mapping Problem
PostPosted: Tue Jan 15, 2008 8:52 pm 
Newbie

Joined: Tue Jan 15, 2008 8:39 pm
Posts: 1
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 16, 2008 3:06 am 
Newbie

Joined: Wed Jan 16, 2008 2:53 am
Posts: 5
it depends on your idea about comment class , if PersonComment class is as same as GameComment class and you want deferent tabel for eachother you can declare only one class Comment and if you make it embeddable in mapping us @CollectionOfElements in Person class and Game class if you want make it entity it's not neccesary to explicity say person and game in Comment class you can only declare Comment class and in Person and Game class like as past use @OneToMany


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

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.