Query query=session.createQuery("from Employee as emp where emp.empName like '%"+name+"%'");
ArrayList likeEmpList=(ArrayList)query.list();我做的是模糊查询,执行到第二行就抛出异常,如下:严重: Servlet.service() for servlet EmployeeServlet threw exception
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of beans.Employee.setDeptNo
at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:215)
at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:185)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3232)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at bo.EmployeeBo.selectEmpByName(EmployeeBo.java:82)
at servlets.EmployeeServlet.doPost(EmployeeServlet.java:60)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: net.sf.cglib.beans.BulkBeanException: beans.Dept$$EnhancerByCGLIB$$b0bc384d cannot be cast to java.lang.Integer
at beans.Employee$$BulkBeanByCGLIB$$56ac0c15.setPropertyValues(<generated>)
at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:212)
... 30 more
Caused by: java.lang.ClassCastException: beans.Dept$$EnhancerByCGLIB$$b0bc384d cannot be cast to java.lang.Integer
... 32 more
谁帮忙解决下,谢了!!!!

解决方案 »

  1.   

    类型转换错误,beans.Dept$$EnhancerByCGLIB$$b0bc384d cannot be cast to java.lang.Integer 
    检查一下你的代码
      

  2.   

    [*]MySQL Tutorial 免费电子书下载
    [*]MySQL Cookbook 免费电子书下载
    [*]MySQL in a Nutshell 免费电子书下载
    [*]MySQL and mSQL 免费电子书下载
    [*]Expert MySQL 免费电子书下载
    [*]MySQL Administrator's Guide 免费电子书下载
    [*]Mastering MySQL 4 免费电子书下载
    [*]MySQL Pocket Reference 免费电子书下载
    [*]MySQL Crash Course 免费电子书下载
    [*]High Performance MySQL 免费电子书下载
    [*]MySQL and PHP from Scratch 免费电子书下载
    [*]MySQL, Second Edition 免费电子书下载
    [*]MySQL: Essential Skills 免费电子书下载
    [*]Understanding MySQL Internals 免费电子书下载
    [*]PHP5 and MySQL Bible 免费电子书下载
    [*]Learning PHP and MySQL 免费电子书下载
    [*]MySQL Certification Study Guide 免费电子书下载
    [*]MySQL Stored Procedure Programming 免费电子书下载
    [*]PHP and MySQL Web Development 免费电子书下载
    [*]MySQL Database Design and Tuning 免费电子书下载
    [*]MySQL Cookbook, 2nd Edition 免费电子书下载
    [*]The Definitive Guide to MySQL, Second Edition 免费电子书下载
    [*]MySQL Phrasebook: Essential Code and Commands 免费电子书下载
    [*]Managing and Using MySQL, 2nd Edition 免费电子书下载
    [*]Sams Teach Yourself MySQL in 10 Minutes 免费电子书下载
    [*]MySQL 5.0 Certification Study Guide 免费电子书下载
    [*]Web Database Applications with PHP &amp; MySQL 免费电子书下载
    [*]Sams Teach Yourself PHP, MySQL and Apache All in One 免费电子书下载
    [*]Mysql Pocket Reference SECOND EDITION 免费电子书下载
    [*]Mysql Enterprise Solutions Alexander “Sasha” Pachev 免费电子书下载
    [*]The Definitive Guide to MySQL 5, Third Edition 免费电子书下载
    [*]Learning PHP and MySQL, Second Edition 免费电子书下载
    [*]Mastering phpMyAdmin 2.11 for Effective MySQL Management 免费电子书下载
    [*]MySQL and Java Developer’s Guide 免费电子书下载
    [*]Mysql Administrator's Guide and dLanguage Reference 免费电子书下载
    [*]PHP and MySQL For Dummies, 2nd Edition  免费电子书下载
    [*]Database Design Manual: using MySQL for Windows 免费电子书下载
    [*]Mastering phpMyAdmin 2.8 for Effective MySQL Management 免费电子书下载
    [*]Beginning PHP5, Apache, and MySQL Web Development 免费电子书下载
    [*]MySQL The definitive guide to using, programming, and administering MySQL 4.1 and 5.0 Third Edition 免费电子书下载
    [*]MySQL and JSP Web Applications: Data-Driven Programming Using Tomcat and MySQL 免费电子书下载
    [*]Build Your Own Database-Driven Website Using PHP &amp; MySQL 免费电子书下载
    [*]Sams Teach Yourself PHP, MySQL and Apache in 24 Hours 免费电子书下载
    [*]Web Database Applications with PHP &amp; MySQL, 2nd Edition 免费电子书下载
    [*]JDBC Metadata, MySQL, and Oracle Recipes: A Problem-Solution Approach 免费电子书下载
    [*]Beginning PHP and MySQL 5: From Novice to Professional, Second Edition 免费电子书下载
    [*]Practical PHP and MySQL Building Eight Dynamic Web Applications 免费电子书下载
    [*]Beginning PHP and MySQL: From Novice to Professional, Third Edition 免费电子书下载
    [*]Setting Up LAMP: Getting Linux, Apache, MySQL, and PHP Working Together 免费电子书下载
    [*]Creating your MySQL Database: Practical Design Tips and Techniques 免费电子书下载
    [*]Professional LAMP: Linux, Apache, MySQL, and PHP5 Web Development 免费电子书下载
    [*]Sams Teach Yourself PHP, MySQL And Apache: All in One, Third Edition 免费电子书下载
    [*]Intrusion Detection Systems with Snort Advanced IDS Techniques Using Snort, Apache, MySQL, PHP, and ACID 免费电子书下载
      

  3.   

    exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of beans.Employee.setDeptNo 是不是别的地报的错
    你看上面好像在设置DeptNo 时
      

  4.   

    在取回数据后身deptNo里注入值时报错,你看看数据库对应的列是什么类型的,是整数类型吗。是否和deptNo吻合
      

  5.   

    回复5楼:
     是整形的,以前都行.注入hibernate后查询语句就不行了。
    部门表的查询就可以, 员工表的查询就不可以。
    数据库里存的数据都符合。