title: java.lang.NumberFormatException: For input string XX while fetching the data from the database
body: <p>I am trying to fetch data from the database. and I am getting the following error.</p>
  
  <pre><code>[Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: An error occurred while converting the nvarchar value to JDBC data type INTEGER.] with root cause
  java.lang.NumberFormatException: For input string: "XX"
  </code></pre>
  
  <p>I know it is trying to convert my string into integer. but I dont understand why it is doing that, because my datatype is string only.</p>
  
  <p>My code looks like:</p>
  
  <p>model:</p>
  
  <pre><code>package com.a.spring.models;
  
  import java.util.Date;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.OneToOne;
  import javax.persistence.Table;
  
  
  @Entity
  @Table(name="CapacityConstraint")
  public class CapacityConstraint {
  
  
      private int DocEntry;
      private String OpCode;
      private String RsrcCd;
      private String Type;
      private Operation operation;
  
      @Id
      @Column(name="DocEntry")
      @GeneratedValue(strategy = GenerationType.AUTO)
      public int getDocEntry() {
          return DocEntry;
      }
  
  
      public void setDocEntry(int DocEntry) {
          this.DocEntry = DocEntry;
      }
  
  
      @Column(name="OpCode")
      public String getOpCode() {
          return OpCode;
      }
  
  
      public void setOpCode(String opCode) {
          OpCode = opCode;
      }
  
  
      @Column(name="RsrcCd")
      public String getRsrcCd() {
          return RsrcCd;
      }
  
  
      public void setRsrcCd(String rsrcCd) {
          RsrcCd = rsrcCd;
      }
  
  
      @Column(name="Type")
      public String getType() {
          return Type;
      }
  
  
      public void setType(String type) {
          Type = type;
      }
  
      @OneToOne
      @JoinColumn(name = "OpCode", nullable = false, insertable = false, updatable = false)
      public Operation getOperation() {
          return operation;
      }
  
  
      public void setOperation(Operation operation) {
          this.operation = operation;
      }
  
  
  }
  </code></pre>
  
  <p>Operation model:</p>
  
  <pre><code>@Entity
  @Table(name="[@IS_OPRMASTER]")
  public class Operation {
      private int docEntry;
      private String OpCode;
      private String OpName;
  
      @Id
      @Column(name="DocEntry")
  
      public int getDocEntry() {
          return docEntry;
      }
      public void setDocEntry(int docEntry) {
          this.docEntry = docEntry;
      }
  
      @Column(name="U_OpCode")
      public String getOpCode() {
          return OpCode;
      }
      public void setOpCode(String opCode) {
          OpCode = opCode;
      }
      @Column(name="U_OpName")
      public String getOpName() {
          return OpName;
      }
      public void setOpName(String opName) {
          OpName = opName;
      }
  
  }
  </code></pre>
  
  <p>function to fetch data:</p>
  
  <pre><code>@Override
      public List&lt;CapacityConstraint&gt; getList() {
          Session session = sessionFactory.getCurrentSession();
          Query query= session.createSQLQuery("SELECT * FROM CapacityConstraint order by docEntry").addEntity(CapacityConstraint.class);
          List &lt;CapacityConstraint&gt; d=query.list();
          return d;
      }
  </code></pre>
  
  <p>Table capacityconstraint </p>
  
  <pre><code>CREATE TABLE [dbo].[CapacityConstraint](
      [DocEntry] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
      [OpCode] [nvarchar](50) NULL,
      [RsrcCd] [nvarchar](50) NULL,
      [Type] [nvarchar](50) NULL,
       CONSTRAINT [PK_CapacityConstraint] PRIMARY KEY CLUSTERED 
  (
      [DocEntry] ASC
  )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  </code></pre>
  
  <p>table Operation</p>
  
  <pre><code>CREATE TABLE [dbo].[@IS_OPRMASTER](
      [DocEntry] [int] NOT NULL,
      [U_OpCode] [nvarchar](20) NULL,
      [U_OpName] [nvarchar](100) NULL,
   CONSTRAINT [KIS_OPRMASTER_PR] PRIMARY KEY CLUSTERED 
  (
      [DocEntry] ASC
  )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  </code></pre>
  
  <p>Stack trace :</p>
  
  <pre><code>Aug 04, 2016 10:52:36 AM org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: Servlet.service() for servlet [kendo] in context with path [/GanttView] threw exception [Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: An error occurred while converting the nvarchar value to JDBC data type INTEGER.] with root cause
  java.lang.NumberFormatException: For input string: "PTHP"
      at java.lang.NumberFormatException.forInputString(Unknown Source)
      at java.lang.Integer.parseInt(Unknown Source)
      at java.lang.Integer.valueOf(Unknown Source)
      at com.microsoft.sqlserver.jdbc.DDC.convertStringToObject(DDC.java:291)
      at com.microsoft.sqlserver.jdbc.DDC.convertStreamToObject(DDC.java:419)
      at com.microsoft.sqlserver.jdbc.ServerDTVImpl.getValue(dtv.java:2007)
      at com.microsoft.sqlserver.jdbc.DTV.getValue(dtv.java:175)
      at com.microsoft.sqlserver.jdbc.Column.getValue(Column.java:113)
      at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getValue(SQLServerResultSet.java:1982)
      at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getValue(SQLServerResultSet.java:1967)
      at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getInt(SQLServerResultSet.java:2219)
      at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:220)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.hibernate.engine.jdbc.internal.proxy.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:104)
      at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
      at com.sun.proxy.$Proxy44.getInt(Unknown Source)
      at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$2.doExtract(IntegerTypeDescriptor.java:66)
      at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:65)
      at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:269)
      at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:265)
      at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238)
      at org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:157)
      at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2807)
      at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1545)
      at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1477)
      at org.hibernate.loader.Loader.getRow(Loader.java:1377)
      at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:644)
      at org.hibernate.loader.Loader.doQuery(Loader.java:854)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:293)
      at org.hibernate.loader.Loader.doList(Loader.java:2382)
      at org.hibernate.loader.Loader.doList(Loader.java:2368)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2198)
      at org.hibernate.loader.Loader.list(Loader.java:2193)
      at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:331)
      at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1780)
      at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:229)
      at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:156)
      at com.kendoui.spring.models.CapacityContraintDaoImpl.getList(CapacityContraintDaoImpl.java:25)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      at com.sun.proxy.$Proxy28.getList(Unknown Source)
      at com.kendoui.spring.controllers.CapacityContraintController.read(CapacityContraintController.java:51)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>It is giving error for the opCode. If I remove the operation model from the capacityConstraint model then it is working fine without giving any error. But if I include it then it is throwing the error. 
  So i think the problem is with the @joinColumn statement.</p>
  
  <p>I would really appreciate if someone could solve my problem.</p>
  
  <p>Thanks in advance.</p>