-->
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.  [ 4 posts ] 
Author Message
 Post subject: SQL Query for Collection object [OneToMany]
PostPosted: Tue Nov 11, 2008 8:30 am 
Newbie

Joined: Tue Nov 11, 2008 7:40 am
Posts: 2
Hi every one

I have three tables Post, Reply and Abuse

One Post may have more than one reply.
Post table and Reply tables have OneToMany relationship.
So when we fetch any Post from DB it also fetches its replies.

If any one reply is abused by users. It will be saved in Abuse table

Here my problem is,
Now, I need to hide those abused reply from my replies collection. But I can't hide that particular reply, though it is coming from collection.

How to leave that reply through sql where condition?
Is it possible to do through annotation?
Is there any other way to achieve this?

(i.e), while selecting all Posts i need to leave that abused reply.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 11, 2008 3:27 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Yes, when mapping a collection, you can add an arbitrary "where" condition, using the "where" attribute plus a SQL where clause.

This is using a mapping file. I don't know if the same effect can be achieved with annotations.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject: Need Further help
PostPosted: Wed Nov 12, 2008 2:12 am 
Newbie

Joined: Tue Nov 11, 2008 7:40 am
Posts: 2
Hi Gonzalo Díaz,

Thank you for your wonderful support.

But i need further help,

I have tried like,

Code:
@OneToMany(mappedBy="threadId")
@Where(clause="reply_id not in (select thread_id from abuse where status='ABUSE')")

but it gives ORA 00904 error for field status.

I have tried like,

Code:
@Where(clause="select * from post where reply_id not in (select thread_id from abuse where status='ABUSE')")

but it give ORA 00936 error.

Note: I need to do some more processes later thats why i kept separate table for abuse. and abuse table has some more columns too

Can you please correct me.


And, I have searched for the Where clause in net. But i cant get any help or material about the @Where clause

Can you give any link to learn more about hibernate clauses

Thank you.

by,
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2008 12:57 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
Please post your mappings and schema.

For information on where clause, see this link

http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/#entity-hibspec-collection

_________________
Please rate this post if you find it helpful


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.