I am trying to integrate spring example of jpetstore with hibernate.
I am getting following error
NFO: category in handleRequest@ ::::::::::::
ct 12, 2005 2:01:22 PM org.springframework.samples.jpetstore.domain.logic .PetStoreImpl getProductListByCategory
NFO: In PetStoreImpl.getProductListByCategory::::
ct 12, 2005 2:01:22 PM org.springframework.samples.jpetstore.dao.hibernat e.HibernateImplProductDao getProductListByCategory
NFO: In HibernateImplProductDao.getProductListByCategory:: :::::::::::FISH
ibernate: select product0_.productid as productid, product0_.category as category2_, product0_.name as name2_, product0_.descn as descn2_ from product product0_ where product0_
ibernate: select category0_.catid as catid0_, category0_.name as name1_0_, category0_.descn as descn1_0_ from category category0_ where category0_.catid=?
ct 12, 2005 2:01:23 PM org.springframework.web.servlet.FrameworkServlet serviceWrapper
EVERE: Could not complete request
rg.springframework.orm.hibernate3.HibernateSystemE xception: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) sette
rg.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of org.springframewo
at org.hibernate.tuple.PojoTuplizer.setPropertyValues WithOptimizer(PojoTuplizer.java:203)
at org.hibernate.tuple.PojoTuplizer.setPropertyValues (PojoTuplizer.java:173)
at org.hibernate.persister.entity.BasicEntityPersiste r.setPropertyValues(BasicEntityPersister.java:2919 )
at org.hibernate.engine.TwoPhaseLoad.initializeEntity (TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndC ollections(Loader.java:523)
at org.hibernate.loader.Loader.doQuery(Loader.java:42 9)
at org.hibernate.loader.Loader.doQueryAndInitializeNo nLazyCollections(Loader.java:211)
at org.hibernate.loader.Loader.doList(Loader.java:158 8)
at org.hibernate.loader.Loader.list(Loader.java:1571)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoa der.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(Que ryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.ja va:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:7 4)
at org.springframework.orm.hibernate3.HibernateTempla te$29.doInHibernate(HibernateTemplate.java:751)
at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:312)
at org.springframework.orm.hibernate3.HibernateTempla te.find(HibernateTemplate.java:742)
at org.springframework.orm.hibernate3.HibernateTempla te.find(HibernateTemplate.java:734)
at org.springframework.samples.jpetstore.dao.hibernat e.HibernateImplProductDao.getProductListByCategory (HibernateImplProductDao.java:32)
at org.springframework.samples.jpetstore.domain.logic .PetStoreImpl.getProductListByCategory(PetStoreImp l.java:151)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:292)
at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:155)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :122)
at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:57)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :144)
at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy1.getProductListByCategory(Unknown Source)
at org.springframework.samples.jpetstore.web.spring.V iewCategoryController.handleRequest(ViewCategoryCo ntroller.java:47)
at org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:44)
at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:684)
at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:625)
at org.springframework.web.servlet.FrameworkServlet.s erviceWrapper(FrameworkServlet.java:386)
at org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:346)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
aused by: net.sf.cglib.beans.BulkBeanException: org.springframework.samples.jpetstore.domain.Categ ory
at org.springframework.samples.jpetstore.domain.Produ ct$$BulkBeanByCGLIB$$1a6b618f.setPropertyValues(<g enerated>)
at org.hibernate.tuple.PojoTuplizer.setPropertyValues WithOptimizer(PojoTuplizer.java:200)
... 51 more
aused by: java.lang.ClassCastException: org.springframework.samples.jpetstore.domain.Categ ory
... 53 more
My petstore.hbm.xml is as follows
My HibernateImplProductDao.java is as follows-Code:<?xml version = "1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name = "org.springframework.samples.jpetstore.domain.Account" table = "account" lazy="false"> <id name="id" type="string" unsaved-value="null" > <column name="userid" sql-type="char(32)" not-null="true"/> <generator class="uuid.hex"/> </id> <property name = "username"/> <property name = "password"/> <property name = "email"/> <property name = "firstName"/> <property name = "lastName"/> <property name = "status"/> <property name = "address1"/> <property name = "address2"/> <property name = "city"/> <property name = "state"/> <property name = "zip"/> <property name = "country"/> <property name = "phone"/> <property name = "favouriteCategoryId"/> <property name = "languagePreference"/> <property name = "listOption"/> <property name = "bannerOption"/> <property name = "bannerName"/> </class> <class name = "org.springframework.samples.jpetstore.domain.Category" table = "category" lazy="false"> <id name="categoryId" type="string" unsaved-value="null" > <column name="catid" sql-type="char(32)" not-null="true"/> <generator class="uuid.hex"/> </id> <property name = "name"/> <property name = "description" column="descn"/> </class> <class name = "org.springframework.samples.jpetstore.domain.Product" table = "product" lazy="false"> <id name="productId" type="string" unsaved-value="null" > <column name="productid" sql-type="char(32)" not-null="true"/> <generator class="uuid.hex"/> </id> <many-to-one name="categoryId" column="category" class="org.springframework.samples.jpetstore.domain.Category" /> <property name = "name"/> <property name = "description" column="descn" /> </class> <class name = "org.springframework.samples.jpetstore.domain.Item" table = "item" lazy="false"> <id name="itemId" type="string" unsaved-value="null" > <column name="itemid" sql-type="char(32)" not-null="true"/> <generator class="uuid.hex"/> </id> <many-to-one name="productId" column="productid" class="org.springframework.samples.jpetstore.domain.Product"/> <property name = "quantity"/> <property name = "product"/> <property name = "supplierId"/> <property name = "listPrice"/> <property name = "unitCost"/> <property name = "status"/> <property name = "attribute1"/> <property name = "attribute2"/> <property name = "attribute3"/> <property name = "attribute4"/> <property name = "attribute5"/> </class> <class name = "org.springframework.samples.jpetstore.domain.Order" table = "orders" lazy="false"> <id name="orderId" type="string" unsaved-value="null" > <column name="orderid" sql-type="char(32)" not-null="true"/> <generator class="uuid.hex"/> </id> <!-- <property name = "orderid"/> --> <property name = "username"/> <property name = "orderDate"/> <property name = "shipAddress1"/> <property name = "shipAddress2"/> <property name = "shipCity"/> <property name = "shipState"/> <property name = "shipZip"/> <property name = "shipCountry"/> <property name = "billAddress1"/> <property name = "billAddress2"/> <property name = "billCity"/> <property name = "billState"/> <property name = "billZip"/> <property name = "billCountry"/> <property name = "courier"/> <property name = "totalPrice"/> <property name = "billToFirstName"/> <property name = "shipToFirstName"/> <property name = "shipToLastName"/> <property name = "creditCard"/> <property name = "expiryDate"/> <property name = "cardType"/> <property name = "locale"/> <property name = "status"/> </class> </hibernate-mapping>
Code:package org.springframework.samples.jpetstore.dao.hibernate; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.dao.DataAccessException; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import org.springframework.samples.jpetstore.dao.ProductDao; import org.springframework.samples.jpetstore.domain.Product; import org.hibernate.classic.*; public class HibernateImplProductDao extends HibernateDaoSupport implements ProductDao { protected final Log logger = LogFactory.getLog(getClass()); public HibernateImplProductDao() { super(); } public List getProductListByCategory(String categoryId) throws DataAccessException { logger.info("In HibernateImplProductDao.getProductListByCategory:::::::::::::"+ categoryId); //return getHibernateTemplate().find("select productid, name, descn, category from product where category like %? "); return getHibernateTemplate().find("from Product as product where product.categoryId like \'"+categoryId+"\'"); // I am getting error here } public Product getProduct(String productId) throws DataAccessException { logger.info("In HibernateImplProductDao.getProduct:::::::::::::"); return (Product) getHibernateTemplate().find("select productid, name, descn, category from product where productid like % ?"); } public List searchProductList(String keywords) throws DataAccessException { logger.info("In HibernateImplProductDao.searchProductList:::::::::::::"); Object parameterObject = new ProductSearch(keywords); return getHibernateTemplate().find("select productid, name, descn, category from product"); } /* Inner Classes */ public static class ProductSearch { protected final Log logger = LogFactory.getLog(getClass()); private List keywordList = new ArrayList(); public ProductSearch(String keywords) { logger.info("In HibernateImplProductDao$ProductSearch.ProductSearch:(This is constructor)::::::::::::"); StringTokenizer splitter = new StringTokenizer(keywords, " ", false); while (splitter.hasMoreTokens()) { this.keywordList.add("%" + splitter.nextToken() + "%"); } } public List getKeywordList() { logger.info("In HibernateImplProductDao$ProductSearch.getKeywordList::::::::::::"); return keywordList; } } }


Reply With Quote