-->
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: Restricitions.contains() ?
PostPosted: Thu Feb 09, 2006 7:14 am 
Newbie

Joined: Thu Feb 09, 2006 4:07 am
Posts: 3
Wouldn't it be nice if the class Restrictions would provide a method like
Code:
static Criterion Restrictions.contains(String propertyName, Object[] values)
I am aware of the existence of the method
Code:
static Criterion Restrictions.in(String propertyName, Object[] values)
but that's not what I want.

This is the case where you might use it:
Consider two entities with a many-to-many relationship, say
Code:
Document *----------*Keyword

One of the usecases is: show me all documents which contain at least an array of keywords K1, K2 and K3 (an array of variable length).

Actualy, I haven't found an elegant way to implement something similar using criteria or HQL.Anyone an elegant alternative (I've tried with Restrictions.sqlRestriction(), but ran into problems)? Or can this be considered as a valid feature request?

Regards,
Bruno.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 12:50 pm 
Newbie

Joined: Thu Feb 09, 2006 4:07 am
Posts: 3
Let me clarify:

The corresponding SQL for
Code:
Restrictions.contains(String prop, Object[] array)
should be something like:
Code:
array.length = n;
n = (select count(*) from <table> where <table>.prop in (array[0], ..., array[n]));

In human language: for a given document, the number of associated keywords which appear in the array equals the number of keywords in the array.

However, this doesn't seem te work for a simple test-case (due to my limited SQL skills?). Hence my request for an elegant solution.


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.