-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: IllegalArgumentException on setter
PostPosted: Fri Dec 21, 2007 5:32 pm 
Beginner
Beginner

Joined: Tue Apr 24, 2007 12:53 pm
Posts: 28
Hibernate version:3.2.5

Mapping documents:
Code:
<hibernate-mapping package="my.companies.package.domain">
    <class name="Member" table="Member" lazy="false" >
        <id name="customerId"
                type="java.lang.Integer" >
               
                <column name="CUST_ID" sql-type="smallint" />
         </id>
    </class>
</hibernate-mapping>


Now, theres alot more to my mapping that this, but what you see is the core of my problem.

This occurs in both HSQLDB & DB2.

When I run the schema export tool for the HSQLDB table, it creates a table with a smallint type column. This maps to a Short. I run a SQL-query which uses an AliasToBeanResultTransformer and the following occurs:

Code:
org.springframework.orm.hibernate3.HibernateSystemException: IllegalArgumentException occurred while calling setter of xxxxxxx.Member.customerId; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of xxxxxxxx.Member.customerId
org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of xxxxxx.Member.customerId
   at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:104)
   at org.hibernate.transform.AliasToBeanResultTransformer.transformTuple(AliasToBeanResultTransformer.java:65)
   at org.hibernate.hql.HolderInstantiator.instantiate(HolderInstantiator.java:69)
   at org.hibernate.loader.custom.CustomLoader.getResultList(CustomLoader.java:330)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
   at org.hibernate.loader.Loader.list(Loader.java:2099)
   at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
   at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
   at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
   at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
   at xxxxxxxx.MemberQueryCallback.doInHibernate(MemberQueryCallback.java:164)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
   at org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:336)
   at xxxxxxxxx.MemberDao.findMembers(MemberDao.java:43)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
   at java.lang.reflect.Method.invoke(Method.java:391)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:291)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:180)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:147)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:169)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:169)
   at $Proxy1.findMembers(Unknown Source)
   at xxxxxxx.MemberDaoTest.testFindMembers(MemberDaoTest.java:177)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
   at java.lang.reflect.Method.invoke(Method.java:391)
   at junit.framework.TestCase.runTest(TestCase.java:164)
   at junit.framework.TestCase.runBare(TestCase.java:130)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:120)
   at junit.framework.TestSuite.runTest(TestSuite.java:230)
   at junit.framework.TestSuite.run(TestSuite.java:225)
   at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
   at java.lang.reflect.Method.invoke(Method.java:391)
   at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
   ... 45 more




Whatever is reading the values from the result set, is stating that the customerId is of type Short. While this is true because that's what the database table states, my entity has getters/setters for an Integer.

Is there anyway to coerce or up-cast this value to the Integer so i don't get this error? Or tell the transformer to do this?

-B


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 26, 2007 7:49 am 
Newbie

Joined: Thu Aug 16, 2007 3:02 am
Posts: 12
Location: Banglore
hi,
Can you check the existing data in database.Any data having value in BigInt size?.Once I got the same error because of the wrong data in database.

_________________
sirajulmuneer


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 26, 2007 9:44 am 
Beginner
Beginner

Joined: Tue Apr 24, 2007 12:53 pm
Posts: 28
It's not possible for there to be a "BigInt" value in the database when the column is already defined as "smallint".

The problem is that my POJO's setter and property are defined as Integers. But due to the definition of the database column, the value is returned as a Short.

Is there a way to tell Hibernate when using a SQL Query and/or Result Transformer that a particular column is of a particular type?

-B


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 26, 2007 2:56 pm 
Newbie

Joined: Thu Aug 16, 2007 3:02 am
Posts: 12
Location: Banglore
hi,
I mean wrong data.not the size.(sorry in that).Here customer Id is primary key so check whether primary key constraint in databse is given or not.If not check any possibility of null value in database.


1.one way of specifying the return datatype is
<sql-query name="mySqlQuery">
<return-scalar column="name" type="string"/>
<return-scalar column="age" type="long"/>
SELECT p.NAME AS name,
p.AGE AS age,
FROM PERSON p WHERE p.NAME LIKE 'Hiber%'
</sql-query>

2.other wise can use method

cast(exprn as hibernate-type) to convert to a specific datatype


3.can use custom data type too

_________________
sirajulmuneer


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.