title: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCExcep tion: could not execute query
body: <p>Hi I have researched this in these forums thoroughly and many people have posted stuff but none of that helps me.</p>
  
  <p>my object:</p>
  
  <pre><code>@Entity
  @Table(name = "ADDRESS")
  @NamedQuery(name = "Address.findByRegistrationId", query = "SELECT a FROM Address a WHERE a.registration_id = :registration_id")
  public class Address {
  
  @Id
  @Column(name = "ADDRESS_ID")
  @GeneratedValue(strategy = GenerationType.AUTO)
  private long address_id;
  
  @Column(name = "REGISTRATION_ID")
  private long registration_id;
  
  public long getRegistration_id() {
      return registration_id;
  }
  
  public void setRegistration_id(long registration_id) {
      this.registration_id = registration_id;
  }
  </code></pre>
  
  <p>my repository implementation:</p>
  
  <pre><code>@Repository
  public class AddressRepositoryJpa implements AddressRepository {
  private final Logger log = Logger.getLogger(AddressRepositoryJpa.class.getName());
  
  @PersistenceContext
  private EntityManager entityManager;
  
  @Override
  public Address findByID(int id) {
      return entityManager.find(Address.class, id);
  }
  
  @Override
  public Address findByRegistrationID(Long registration_id) {
      TypedQuery&lt;Address&gt; query = (TypedQuery&lt;Address&gt;) entityManager.createNamedQuery("Address.findByRegistrationId", Address.class);
      query.setParameter("registration_id", registration_id);
      Address address = (Address) query.getSingleResult();
      return address;
  }
  </code></pre>
  
  <p>my persistence.xml</p>
  
  <pre><code>&lt;bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close"&gt;
      &lt;property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/&gt;
      &lt;property name="username" value="xxxx"/&gt;
      &lt;property name="password" value="xxxxx"/&gt;
      &lt;property name="url" value="jdbc:oracle:thin:@//xxxxx:1521/XXX.XXX.XXX.XX.XX"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/&gt;
      &lt;/property&gt;
      &lt;property name="jpaProperties"&gt;
          &lt;map&gt;&lt;!--validate | update | create | create-drop--&gt;
              &lt;entry key="hibernate.hbm2ddl.auto" value="update"/&gt;
              &lt;entry key="hibernate.show_sql" value="true"/&gt;
              &lt;entry key="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/&gt;
          &lt;/map&gt;
      &lt;/property&gt;
      &lt;property name="packagesToScan" value="edu.rmit.core.entities"/&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven/&gt;
  &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"/&gt;
  </code></pre>
  
  <p>I have tried named queries and even one without parameters as a list and no luck, I wonder if there is any special configuration I need to do.</p>
  
  <p>The entitymanager.find method works, so the connection to the db is fine.</p>
  
  <p>Thanks a lot.</p>
  
  <p>stacktrace:</p>
  
  <pre><code>Hibernate: select address0_.ADDRESS_ID as ADDRESS_ID1_0_, address0_.ADDRESS_1 as
   ADDRESS_2_0_, address0_.ADDRESS_2 as ADDRESS_3_0_, address0_.ADDRESS_3 as ADDRE
  SS_4_0_, address0_.ADDRESS_TYPE as ADDRESS_TYPE5_0_, address0_.CITY as CITY6_0_,
   address0_.COUNTRY as COUNTRY7_0_, address0_.CREATED_BY as CREATED_BY8_0_, addre
  ss0_.CREATED_ON as CREATED_ON9_0_, address0_.MODIFIED_BY as MODIFIED_BY10_0_, ad
  dress0_.MODIFIED_ON as MODIFIED_ON11_0_, address0_.POSTCODE as POSTCODE12_0_, ad
  dress0_.REGISTRATION_ID as REGISTRATION_ID13_0_, address0_.STATE as STATE14_0_,
  address0_.STUDENT_ID as STUDENT_ID15_0_ from ADDRESS address0_ where address0_.R
  EGISTRATION_ID=?
  javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCExcep
  tion: could not execute query
          at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntit
  yManagerImpl.java:1763)
          at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntit
  yManagerImpl.java:1677)
          at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:5
  24)
          at edu.rmit.core.repositories.jpa.AddressRepositoryJpa.findByRegistratio
  nID(AddressRepositoryJpa.java:36)
          at edu.rmit.core.services.impl.AddressServiceImpl.findByRegistrationID(A
  ddressServiceImpl.java:28)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
  java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
  sorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:497)
          at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflecti
  on(AopUtils.java:317)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJo
  inpoint(ReflectiveMethodInvocation.java:190)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
  ReflectiveMethodInvocation.java:157)
          at org.springframework.transaction.interceptor.TransactionInterceptor$1.
  proceedWithInvocation(TransactionInterceptor.java:98)
          at org.springframework.transaction.interceptor.TransactionAspectSupport.
  invokeWithinTransaction(TransactionAspectSupport.java:262)
          at org.springframework.transaction.interceptor.TransactionInterceptor.in
  voke(TransactionInterceptor.java:95)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
  ReflectiveMethodInvocation.java:179)
          at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynami
  cAopProxy.java:207)
          at com.sun.proxy.$Proxy1621.findByRegistrationID(Unknown Source)
          at edu.rmit.rest.mvc.OrderSummaryController.getOrderSummaryMapByID(Order
  SummaryController.java:79)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
  java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
  sorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:497)
          at org.springframework.web.method.support.InvocableHandlerMethod.invoke(
  InvocableHandlerMethod.java:215)
          at org.springframework.web.method.support.InvocableHandlerMethod.invokeF
  orRequest(InvocableHandlerMethod.java:132)
          at org.springframework.web.servlet.mvc.method.annotation.ServletInvocabl
  eHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
          at org.springframework.web.servlet.mvc.method.annotation.RequestMappingH
  andlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
          at org.springframework.web.servlet.mvc.method.annotation.RequestMappingH
  andlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
          at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapt
  er.handle(AbstractHandlerMethodAdapter.java:83)
          at org.springframework.web.servlet.DispatcherServlet.doDispatch(Dispatch
  erServlet.java:938)
          at org.springframework.web.servlet.DispatcherServlet.doService(Dispatche
  rServlet.java:870)
          at org.springframework.web.servlet.FrameworkServlet.processRequest(Frame
  workServlet.java:961)
          at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServl
  et.java:852)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
          at org.springframework.web.servlet.FrameworkServlet.service(FrameworkSer
  vlet.java:837)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
  icationFilterChain.java:303)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
  ilterChain.java:208)
          at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52
  )
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
  icationFilterChain.java:241)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
  ilterChain.java:208)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
  alve.java:220)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
  alve.java:122)
          at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
  torBase.java:505)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
  ava:170)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
  ava:103)
          at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
  956)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
  ve.java:116)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
  a:423)
          at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp
  11Processor.java:1079)
          at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
  AbstractProtocol.java:625)
          at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpo
  int.java:2522)
          at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoin
  t.java:2511)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
  java:1142)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
  .java:617)
          at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskTh
  read.java:61)
          at java.lang.Thread.run(Thread.java:745)
  Caused by: org.hibernate.exception.GenericJDBCException: could not execute query
  
          at org.hibernate.exception.internal.StandardSQLExceptionConverter.conver
  t(StandardSQLExceptionConverter.java:54)
          at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlException
  Helper.java:126)
          at org.hibernate.loader.Loader.doList(Loader.java:2556)
          at org.hibernate.loader.Loader.doList(Loader.java:2539)
          at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2369)
          at org.hibernate.loader.Loader.list(Loader.java:2364)
          at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:496)
          at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslat
  orImpl.java:387)
          at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.
  java:231)
          at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1264)
          at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
          at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573)
          at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:4
  95)
          ... 54 more
  Caused by: java.sql.SQLException: Fail to convert to internal representation
          at oracle.jdbc.driver.CharCommonAccessor.getInt(CharCommonAccessor.java:
  147)
          at oracle.jdbc.driver.T4CVarcharAccessor.getInt(T4CVarcharAccessor.java:
  818)
          at oracle.jdbc.driver.OracleResultSetImpl.getInt(OracleResultSetImpl.jav
  a:928)
          at oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:434)
          at org.apache.commons.dbcp2.DelegatingResultSet.getInt(DelegatingResultS
  et.java:283)
          at org.apache.commons.dbcp2.DelegatingResultSet.getInt(DelegatingResultS
  et.java:283)
          at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$2.doExtract(I
  ntegerTypeDescriptor.java:74)
          at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtract
  or.java:64)
          at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStan
  dardBasicType.java:267)
          at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStan
  dardBasicType.java:263)
          at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStan
  dardBasicType.java:253)
          at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandard
  BasicType.java:338)
          at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(Abstra
  ctEntityPersister.java:2969)
          at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1695)
          at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1627)
          at org.hibernate.loader.Loader.getRow(Loader.java:1514)
          at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:725)
          at org.hibernate.loader.Loader.processResultSet(Loader.java:952)
          at org.hibernate.loader.Loader.doQuery(Loader.java:920)
          at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Lo
  ader.java:354)
          at org.hibernate.loader.Loader.doList(Loader.java:2553)
          ... 64 more
  </code></pre>