-->
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: Searching a bag of keywords?
PostPosted: Mon Sep 08, 2003 11:30 am 
Two tables that this problem relates to are BUSINESS and BUSINESS_KEYWORD. The keyword table contains a BUSINESS_ID and a KEYWORD (string value). The idea is that we can associate keywords to businesses and search for a business by that keyword (where keyword like 'food%' say). I have it mapped currently as a bag:

Code:
    <bag      name="keywords"
              lazy="true"
           inverse="false"
             table="BUSINESS_KEYWORD"
           cascade="all-delete-orphan"
          order-by="KEYWORD ASC">
      <key     column="BUSINESS_ID" />
      <element column="KEYWORD" type="string" />
    </bag>


The sorting is for administrative use only (easier to find one out of a 100 if they're sorted). Anyway, I basically want to do an SQL query like:

Code:
SELECT ...
   FROM BUSINESS, BUSINESS_KEYWORD
WHERE BUSINESS.BUSINESS_ID = BUSINESS_KEYWORD.BUSINESS_ID AND
       BUSINESS_KEYWORD.KEYWORD LIKE 'food%'


I can't find anything in the Hibernate doco's about how to do a query like this though. All the examples are indexed bags. Is there any way to do something like:

Code:
  from com.sa.go.bto.Business b
where b.keywords like 'food%'
(or b.keywords[], b.keywords[%], ...)


Thanks!
James


Top
  
 
 Post subject: you can use a filter
PostPosted: Mon Sep 08, 2003 11:34 am 
Beginner
Beginner

Joined: Thu Sep 04, 2003 2:50 pm
Posts: 45
Location: US: New York NY
session.filter() see api docs.

here is how I do something similar ... this.status.name is filtering on many-to-one attribute

Object[] values = new Object[3];
values[0] = "published";
values[1] = new java.util.Date();
values[2] = new java.util.Date();
net.sf.hibernate.type.Type[] types = new net.sf.hibernate.type.Type[3];
types[0] = Hibernate.STRING;
types[1] = Hibernate.DATE;
types[2] = Hibernate.DATE;
java.util.List playlists = (java.util.List)sess.filter(frame.getList(),
"where this.status.name = ? and (this.showEdate is null or this.showEdate > ?) and (this.showSdate is null or this.showSdate <= ?) order by sort_order",
values,
types);


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 08, 2003 11:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Code:
from Business b
join b.keywords kw
where kw like 'food%'

But this only works in Hibernate 2.1, because it is a collection of values, not an association.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 08, 2003 12:03 pm 
gavin wrote:
Code:
from Business b
join b.keywords kw
where kw like 'food%'



worked like a charm. you rule gavin!


Top
  
 
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.