Cannot query with criteria is like below
Hibernate version:
Mapping documents: <class name="Contents" table="T_CONTENTS" proxy="Contents"> <id name="id" column="CONTENTS_ID" unsaved-value="null"> <generator class="uuid.hex"/> </id> <property name="title" not-null="true" column="F_TITLE"/> <property name="brief" column="F_BRIEF"/> <property name="content" column="F_CONTENT"/> <property name="createDate" column="F_CREATED" type="java.util.Date" not-null="true"/> <property name="status" column="F_STATUS"/> <many-to-one name="category" column="CATEGORY_ID" class="Category" not-null="true" /> <!-- <set name="images" lazy="true" table="T_IMAGES" order-by="F_TITLE asc"> <key column="CONTENTS_ID"/> <composite-element class="Image"> <property name="title" column="F_TITLE"/> <property name="description" column="F_DESCRIPTION"/> <property name="path" column="F_PATH"/> <property name="thumbnail" column="F_THUMBNAIL"/> <property name="createDate" column="F_CREATED" type="java.util.Date" not-null="true"/> </composite-element> </set> --> </class>
Code between sessionFactory.openSession() and session.close(): public Collection findByCategory(String categoryID) throws InfrastructureException { Collection result=new ArrayList(); Session session = HibernateUtil.getSession(); Category cat = null;
try { cat = (Category) session.load(Category.class, categoryID); } catch (HibernateException e) { throw new InfrastructureException(e); } Criteria crit = HibernateUtil.getSession().createCriteria( Contents.class); Contents c = new Contents(); c.setCreateDate(null); System.out.print(cat.getId()); c.setCategory(cat); try { result= crit.add(Example.create(c)).list(); } catch (HibernateException e1) { throw new InfrastructureException(e1); } System.out.print(result.size()); return result;
}
The generated SQL (show_sql=true): Hibernate: select this.CONTENTS_ID as CONTENTS1_0_, this.F_TITLE as F_TITLE0_, t his.F_BRIEF as F_BRIEF0_, this.F_CONTENT as F_CONTENT0_, this.F_CREATED as F_CRE ATED0_, this.F_STATUS as F_STATUS0_, this.CATEGORY_ID as CATEGORY7_0_ from T_CON TENTS this where 1=1
the query seem wrong
How do I can query by category ?
|