-->
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.  [ 1 post ] 
Author Message
 Post subject: Help--About nesting query
PostPosted: Tue May 27, 2008 5:26 am 
Newbie

Joined: Tue May 27, 2008 5:14 am
Posts: 1
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!


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

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.