I have an entity:
@Entity
@Table(name = "TopicOrReply")
public class TopicOrReply implements Serializable{
private Long id;
private String randomCode;
private String title;
private String content;
private TopicOrReply repliedTopic;
....
}
Explain:
when title is NOT null, this records means a topic. repliedTopic is null in this case.
when title is null, this records means a reply. repliedTopic is NOT null in this case.
---------------------
Now, i want to query out a topic with id[1] and its replies.
Here is my code:
Criteria criteria = ((org.hibernate.Session) em.getDelegate()).createCriteria(TopicOrReply.class);
Criteria subCriteria = criteria.createCriteria("repliedTopic");
subCriteria.add(Restrictions.and(
Restrictions.eq("id",this.getTopicId()),
Restrictions.eq("randomCode",this.getRandomCode())
));
---------------------
But those codes only fetch replies!
I have read "Hibernate in action" and searched through google, But got nothing usefull.
Please Help Me! It has tortured me several days!!!
Any tips are appreciated!
Thanks ahead!
|