Announcement Announcement Module
Collapse
No announcement yet.
Spring -hibernate Integration (CGLIB error) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring -hibernate Integration (CGLIB error)

    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


    Code:
    <?xml version = "1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
              "http&#58;//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&#40;32&#41;" 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&#40;32&#41;" 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&#40;32&#41;" 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&#40;32&#41;" 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&#40;32&#41;" 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>
    My HibernateImplProductDao.java is as follows-

    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 &#123;
    
        protected final Log logger = LogFactory.getLog&#40;getClass&#40;&#41;&#41;;
    
    
        public HibernateImplProductDao&#40;&#41;
        &#123;
            super&#40;&#41;;
        &#125;
      public List getProductListByCategory&#40;String categoryId&#41; throws DataAccessException &#123;
        logger.info&#40;"In HibernateImplProductDao.getProductListByCategory&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;"+ categoryId&#41;;
    
        //return getHibernateTemplate&#40;&#41;.find&#40;"select productid, name, descn, category from product where category like %? "&#41;;
      
    
    
        return getHibernateTemplate&#40;&#41;.find&#40;"from Product as product where product.categoryId like \'"+categoryId+"\'"&#41;;
        
        // I am getting error here
    
    
      &#125;
    
      public Product getProduct&#40;String productId&#41; throws DataAccessException &#123;
        logger.info&#40;"In HibernateImplProductDao.getProduct&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;"&#41;;
    
        return &#40;Product&#41; getHibernateTemplate&#40;&#41;.find&#40;"select productid, name, descn, category from product where productid like % ?"&#41;;
      &#125;
    
      public List searchProductList&#40;String keywords&#41; throws DataAccessException &#123;
        logger.info&#40;"In HibernateImplProductDao.searchProductList&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;"&#41;;
        Object parameterObject = new ProductSearch&#40;keywords&#41;;
        return getHibernateTemplate&#40;&#41;.find&#40;"select productid, name, descn, category from product"&#41;;
      &#125;
    
    
      /* Inner Classes */
    
      public static class ProductSearch &#123;
         protected final Log logger = LogFactory.getLog&#40;getClass&#40;&#41;&#41;;
        private List keywordList = new ArrayList&#40;&#41;;
    
        public ProductSearch&#40;String keywords&#41; &#123;
            logger.info&#40;"In HibernateImplProductDao$ProductSearch.ProductSearch&#58;&#40;This is constructor&#41;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;"&#41;;
    
          StringTokenizer splitter = new StringTokenizer&#40;keywords, " ", false&#41;;
          while &#40;splitter.hasMoreTokens&#40;&#41;&#41; &#123;
            this.keywordList.add&#40;"%" + splitter.nextToken&#40;&#41; + "%"&#41;;
          &#125;
        &#125;
    
    
        public List getKeywordList&#40;&#41; &#123;
          logger.info&#40;"In HibernateImplProductDao$ProductSearch.getKeywordList&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;&#58;"&#41;;
    
          return keywordList;
        &#125;
      &#125;
    
    &#125;

  • #2
    Can you switch the property hibernate.cglib.use_reflection_optimizer to false in your Hibernate config and post again - it gives slightly more detailed error reporting with this.

    Rob

    Comment

    Working...
    X