hibernate java.lang.IllegalArgumentException问题解决

上周遇到了这个问题,参数异常,我以为是hibernate 的关系,结果换了JDBC来弄就好了,也没去深究到底是什么原因。今天又遇到这个问题了,和师父同时解决了这个问题。
问题概述:
在由数据库里的表反转实体(自动生成)之后,进行Hibernate查询,tomcat报java.lang.IllegalArgumentException参数异常。如下。
 1 2013-12-30 16:37:54 org.apache.catalina.core.StandardWrapperValve invoke
 2 严重: Servlet.service() for servlet struts threw exception
 3 java.lang.IllegalArgumentException
 4     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 5     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 6     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 7     at java.lang.reflect.Method.invoke(Method.java:597)
 8     at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:66)
 9     at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:360)
10     at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:221)
11     at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3594)
12     at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:152)
13     at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:877)
14     at org.hibernate.loader.Loader.doQuery(Loader.java:752)
15     at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
16     at org.hibernate.loader.Loader.doList(Loader.java:2228)
17     at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
18     at org.hibernate.loader.Loader.list(Loader.java:2120)
19     at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
20     at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
21     at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
22     at cn.gx.lms.orgmanager.dao.CustomOrgManagerDaoImpl.queryLiftTypeDic(CustomOrgManagerDaoImpl.java:1924)
23     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
24     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
25     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
26     at java.lang.reflect.Method.invoke(Method.java:597)
27     at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
28     at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
29     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
30     at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
31     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
32     at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
33     at $Proxy22.queryLiftTypeDic(Unknown Source)
34     at cn.gx.lms.orgmanager.service.CustomOrgManagerServiceImpl.queryLiftTypeDic(CustomOrgManagerServiceImpl.java:611)
35     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
36     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
37     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
38     at java.lang.reflect.Method.invoke(Method.java:597)
39     at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
40     at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
41     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
42     at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
43     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
44     at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
45     at $Proxy27.queryLiftTypeDic(Unknown Source)
46     at cn.gx.lms.orgmanager.action.CustomOrgManagerAction.liftTypeAndScopeAdd(CustomOrgManagerAction.java:2114)
47     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
48     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
49     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
50     at java.lang.reflect.Method.invoke(Method.java:597)
51     at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
52     at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
53     at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
54     at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
55     at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
56     at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
57     at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
58     at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
59     at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
60     at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
61     at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
62     at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
63     at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
64     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
65     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
66     at cn.gx.lms.common.filter.CodeEncodeClass.doFilter(CodeEncodeClass.java:29)
67     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
68     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
69     at cn.gx.lms.common.filter.AntiSqlInjectionfilter.doFilter(AntiSqlInjectionfilter.java:53)
70     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
71     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
72     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
73     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
74     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
75     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
76     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
77     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
78     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
79     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
80     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
81     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
82     at java.lang.Thread.run(Thread.java:619)

在DAO层的检索如下(采用Criteria面向对象的检索):

 1 @SuppressWarnings("unchecked")
 2     @Transactional(propagation = Propagation.NOT_SUPPORTED)
 3     public List<LmsLiftTypeDic> queryLiftTypeDic(Map<String, String> conditions) {
 4         Criteria c = super.getSessionFactory().getCurrentSession()
 5                 .createCriteria(LmsLiftTypeDic.class);
 6         String dicType = conditions.get("dicType");
 7         if (StringUtil.validateStringNotNull(dicType)) {
 8             c.add(Restrictions.eq("dicType", dicType));
 9         }
10         return c.list();
11     }

实体对应的hbm文件:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 3 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 4 <!-- Mapping file autogenerated by MyEclipse Persistence Tools -->
 5 <hibernate-mapping>
 6     <class name="cn.gx.lms.domain.LmsLiftTypeDic" table="LMS_LIFT_TYPE_DIC">
 7         <id name="rowId" type="string">
 8             <column name="ROW_ID" length="32" />
 9             <generator class="uuid.hex" />
10         </id>
11         <property name="dicName" type="string">
12             <column name="DIC_NAME" length="200" />
13         </property>
14         <property name="dicType" type="string">
15             <column name="DIC_TYPE" length="1" />
16         </property>
17         <property name="orderNum" type="int">
18             <column name="ORDER_NUM" />
19         </property>
20         <property name="createTime" type="date">
21             <column name="CREATE_TIME" length="7" />
22         </property>
23         <property name="extends1" type="string">
24             <column name="EXTENDS_1" length="200" />
25         </property>
26         <property name="extends2" type="date">
27             <column name="EXTENDS_2" length="7" />
28         </property>
29         <property name="extends3" type="int">
30             <column name="EXTENDS_3" />
31         </property>
32     </class>
33 </hibernate-mapping>

 

 

 

经测试,数据库中的number类型经Myeclipse的反向生成实体后,自动生成的类型为long,不可与之对应。将hbm文件和实体类中的long改为int对应的类型即可。目测是myeclipse的生成实体的问题,我再也不相信自动生成这回事儿了。。想省事,还是自己好好检查一番吧。

posted @ 2013-12-30 23:17  拔丝苹果皮  阅读(6171)  评论(0编辑  收藏  举报