-->
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.  [ 6 posts ] 
Author Message
 Post subject: Problem with Int Identifiers - IllegalArgumentException
PostPosted: Tue Apr 06, 2004 7:53 pm 
Newbie

Joined: Mon Apr 05, 2004 12:28 am
Posts: 3
Hi,

I'm having problems using Hibernate to save a class of mine. I'm using Hibernate 1.2.5 (yeah, old, haven't seen a need to upgrade yet).

I won't paste the entire declaration but here's the gist:

Code:
public class Claim{

    // identifier
    private int claimId;

    // more stuff here.....

    public void setClaimId(int id){ claimId = id; }
    public int getClaimId(){ return claimId; }
    // more stuff here....
};


Mapping excerpt....


Code:

<hibernate-mapping>
    <class name="reuse.Claim" table="Claims.Claims" mutable="true">
   <id name="claimId" column="claimId" type="int">
       <generator class="native"/>
   </id>
........



So yeah, I noticed the problem and made a small servlet to test it:

Code:
public class TestServlet extends HttpServlet {
   public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
      Claim myClaim = new Claim();
      myClaim.setDescription("blah");
      
      Datastore ds = Hibernate.createDatastore();
      SessionFactory sf;
      Session session;
      try{
         ds.storeClass(reuse.Claim.class);
         sf = ds.buildSessionFactory();
         session = sf.openSession();
         
         session.save(myClaim);
         
      }
      catch (Exception e) {
         PrintWriter out = response.getWriter();
         e.printStackTrace(out);
      }
   }   
}


And here's what I get when I run it:

Code:
java.lang.IllegalArgumentException: argument type mismatch
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at cirrus.hibernate.helpers.ReflectHelper$Setter.set(ReflectHelper.java:39)
   at cirrus.hibernate.persister.AbstractEntityPersister.setIdentifier(AbstractEntityPersister.java:289)
   at cirrus.hibernate.impl.SessionImpl.doSave(SessionImpl.java:574)
   at cirrus.hibernate.impl.SessionImpl.save(SessionImpl.java:486)
   at reuse.servlet.TestServlet.doGet(TestServlet.java:44)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:577)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1040)
   at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1151)
   at java.lang.Thread.run(Thread.java:534)
rethrown as cirrus.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling: argument type mismatch setter of reuse.Claim.claimId
   at cirrus.hibernate.helpers.ReflectHelper$Setter.set(ReflectHelper.java:57)
   at cirrus.hibernate.persister.AbstractEntityPersister.setIdentifier(AbstractEntityPersister.java:289)
   at cirrus.hibernate.impl.SessionImpl.doSave(SessionImpl.java:574)
   at cirrus.hibernate.impl.SessionImpl.save(SessionImpl.java:486)
   at reuse.servlet.TestServlet.doGet(TestServlet.java:44)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:577)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1040)
   at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1151)
   at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at cirrus.hibernate.helpers.ReflectHelper$Setter.set(ReflectHelper.java:39)
   ... 34 more




Someone else I now had similar problems and said it had something to do with the native identifiers returning a long.

Anyone know what I'm doing wrong? Am I not able to use ints as my identifiers? Thanks for any help


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 09, 2004 10:56 am 
Newbie

Joined: Mon Apr 05, 2004 12:28 am
Posts: 3
Did I not include enough information? Is there something else needed to answer my question? Did I stump everyone?

Can someone at least please confirm whether or not I can use integer identifiers?

Thanks for any help....


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 17, 2004 1:30 pm 
Beginner
Beginner

Joined: Thu Mar 25, 2004 9:13 am
Posts: 20
I am running to the same exact problem, wishing for some help!!!

_________________
Oren Gross


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 17, 2004 1:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Old versions of Hibernate did not support int as an identifier type with native id generator.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 17, 2004 2:12 pm 
Beginner
Beginner

Joined: Thu Mar 25, 2004 9:13 am
Posts: 20
But I am using hibernate-2.1

this is what I get:
Code:
22:06:16,352 ERROR [BasicPropertyAccessor] IllegalArgumentException in class: com.snap.businessobjects.network.Network, setter method of property: id
22:06:16,352 ERROR [BasicPropertyAccessor] expected type: int, actual value: java.lang.String


While:
Code:
<id name="id" type="integer" unsaved-value="null">
            <column name="NET_ID" sql-type="integer" not-null="true"/>
            <generator class="uuid.hex"/>
</id>


And the database is Integer (SQL Server 2000)

_________________
Oren Gross


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 17, 2004 2:17 pm 
Regular
Regular

Joined: Wed Mar 03, 2004 9:38 am
Posts: 70
If you had read the documentation, you would have noticed that uuid.hex generates String:s, not int:s.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.