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