Looks like you need to add your category class/hbm.xml to the session factory configuration. Which version of AppFuse are you using? If 2.0-m*, then you should add the classname to hibernate.cfg.xml.
Mike On 5/2/07, sionsmith <[EMAIL PROTECTED]> wrote:
I've tried that - neither worked - mayb i have something in my Category.class wrong? this is the error i got: ======= EXCEPTION ====== Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java :39) at sun.reflect.DelegatingMethodAccessorImpl.invoke( DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.myfaces.el.PropertyResolverImpl.getProperty( PropertyResolverImpl.java:457) ... 86 more Caused by: org.springframework.orm.hibernate3.HibernateQueryException: Categories is not mapped [from Categories where male_only= :maleOnly]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: Categories is not mapped [from Categories where male_only= :maleOnly] at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException (SessionFactoryUtils.java:640) at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException (HibernateAccessor.java:412) at org.springframework.orm.hibernate3.HibernateTemplate.execute( HibernateTemplate.java:372) at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedParam( HibernateTemplate.java:861) at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedParam( HibernateTemplate.java:852) at com.grabandshare.server.categories.CategoryDaoHibernate.getMaleCategories( CategoryDaoHibernate.java:48) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java :39) at sun.reflect.DelegatingMethodAccessorImpl.invoke( DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection( AopUtils.java:299) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke( JdkDynamicAopProxy.java:196) at $Proxy18.getMaleCategories(Unknown Source) at com.grabandshare.server.categories.CategoryManagerImpl.getMaleCategories( CategoryManagerImpl.java:33) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java :39) at sun.reflect.DelegatingMethodAccessorImpl.invoke( DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection( AopUtils.java:299) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke( JdkDynamicAopProxy.java:196) at $Proxy20.getMaleCategories(Unknown Source) at com.grabandshare.client.categories.CategoryList.getInit(CategoryList.java :35) ... 91 more Caused by: org.hibernate.hql.ast.QuerySyntaxException: Categories is not mapped [from Categories where male_only= :maleOnly] at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister( SessionFactoryHelper.java:158) at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement( FromElementFactory.java:87) at org.hibernate.hql.ast.tree.FromClause.addFromElement( FromClause.java:70) at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java :257) at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java :3056) at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList( HqlSqlBaseWalker.java:2945) at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java :688) at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement( HqlSqlBaseWalker.java:281) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java :229) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java :228) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile( QueryTranslatorImpl.java:160) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java :111) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java :77) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java :56) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan( QueryPlanCache.java:72) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan( AbstractSessionImpl.java:133) at org.hibernate.impl.AbstractSessionImpl.createQuery( AbstractSessionImpl.java:112) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java :1623) at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate( HibernateTemplate.java:863) at org.springframework.orm.hibernate3.HibernateTemplate.execute( HibernateTemplate.java:367) ... 110 more Any ideas? Michael Horwitz wrote: > > I think the problem is less your query, more the method you are using on > HibernateTemplate. This should work for you: > > public List<Category> getMaleCategories() { > return getHibernateTemplate().find("from Categories > where male_only=?", Boolean.TRUE); > } > > The named query form of the find method is used when you use named (as > opposed to positional) parameters in your query: > > public List<Category> getMaleCategories() { > return getHibernateTemplate().findByNamedParam("from Categories > where male_only= :maleOnly", "maleOnly", Boolean.TRUE); > } > > Mike. > > > On 5/2/07, sionsmith <[EMAIL PROTECTED]> wrote: >> >> >> Quick questions Guys & Girls - I'm new to hibernate 3 and unsure how to >> write >> the following in a query: >> >> I have a Categories table in the DB, with a boolean flag as one of the >> attributes, i want to return a list of all the items which have the >> boolean >> set to true. This is what i tried using, but it gave me an exception >> >> public List<Category> getMaleCategories() { >> return getHibernateTemplate().findByNamedParam("from Categories >> where male_only=?", "true", Hibernate.BOOLEAN); >> } >> >> I've tried by example object and that didnt seem to return the correct >> set! >> >> Any help would be very greatful :) >> >> Many thanx Sion >> -- >> View this message in context: >> http://www.nabble.com/How-to-query-in-Hibernate-3-tf3680950s2369.html#a10287100 >> Sent from the AppFuse - User mailing list archive at Nabble.com. >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> > > -- View this message in context: http://www.nabble.com/How-to-query-in-Hibernate-3-tf3680950s2369.html#a10290059 Sent from the AppFuse - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]