-->
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
PostPosted: Sat Apr 12, 2008 8:07 pm 
Newbie

Joined: Sat Apr 12, 2008 7:57 pm
Posts: 1
Hi everyone, i'm a beginner with java spring hibernate (I'm using hibernate 3 )

(I don't Know if this is the correct place to post my doubt)

I have this code as part of Content.hbm.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
   
<hibernate-mapping>

   <class name="portal.model.Content" table="content" entity-name="Content">
      <id name="contentID" column="contentID" unsaved-value="null">
         <generator class="native"></generator>
      </id>
      
      <bag name="categories" table="category_x_content" lazy="true" cascade="save-update">
         <key column="contentID" foreign-key="FK_CATEGORY_X_CONTENT_CONTENT"></key>
         <many-to-many class="portal.model.Category" column="categoryID"
            foreign-key="FK_CATEGORY_X_CONTENT_CATEGORY">
         </many-to-many>
      </bag>
      
            
      <property name="text" type="text" column="text"></property>
      <property name="title" type="text" column="title"></property>
      
      
      <many-to-one name="type" class="portal.model.Type" column="typeID" cascade="save-update"
         foreign-key="FK_CONTENT_TYPE">
      </many-to-one>
      
      <property name="creationDate" type="date" column="creation_date"></property>
      <property name="modificationDate" column="modification_date"></property>
      <property name="idx" column="idx"></property>
      
      
   </class>
   
      
</hibernate-mapping>



I needed to get all the contents (e.g) with title or text "something"
So I was doing something like this

Code:
getHibernateTemplate().find(
      "from Content c   where c.title like '%something%' or c.text like '%something%' );


And it worked fine

But now I need to get all the contents with title or text "something" and category "blabla"

So i figured i just needed to do something like this:


Code:
getHibernateTemplate().find(
      "from Content c   where c.title like '%something%' or c.text like '%something%' and c.categories like '%blabla%' );

But I'm getting the following mistake:

Code:
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not execute query; bad SQL grammar[select content0_.contentID as contentID,  content0_.stateID as stateID5_, content0_.text as text5_, content0_.title as title5_, content0_.typeID as typeID5_, content0_.creation_date as creation8_5_, content0_.modification_date as modifica9_5_, content0_.idx as idx5_, category_x_content categories1_, category category2_ where content0_.contentID=categories1_.contentID and categories1_.categoryID=category2_.categoryID and content0_.title5_ like '%something%' or content0_.text5_ like '%something%' and (. like '%blabla%')]; nested exception is java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'like '%a%')' at line 1



So basically the mistake is in here (. like '%blabla%') because what i've wrote was c.categories like '%blabla%'

Does anybody have an idea of what I'm doing wrong?????? (please help me)

Thanks in advanced


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.