title: How to fix "class java.lang.Long cannot be cast to class java.lang.Integer" error in Java, when I want return result list?
body: <p>When I want return result of query and put into list, I get error &quot;java.lang.ClassCastException: class java.lang.Long cannot be cast to class java.lang.Integer (java.lang.Long and java.lang.Integer are in module java.base of loader 'bootstrap')&quot;. I tried to change type values, but the error does not go away.</p>
  <pre><code>Query query = session.createQuery(&quot;SELECT size_file FROM File WHERE storage.id =: storage_id&quot;, Number.class)
                      .setParameter(&quot;storage_id&quot;, storage.getId());
  
              List&lt;Number&gt; list=(List&lt;Number&gt;)query.getResultList();
  </code></pre>
  <pre><code>@Entity
  @Table(name = &quot;FILE_STORAGE&quot;)
  public class File {
  
      @Id
      @Column(name = &quot;ID&quot;)
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int id;
      @Column(name = &quot;NAME&quot;)
      private String name;
      @Column(name = &quot;FORMAT&quot;)
      private String format;
      @Column(name = &quot;SIZE_FILE&quot;)
      private int size_file;
      @OneToOne(cascade = CascadeType.ALL)
      @JoinColumn(name = &quot;STORAGE_ID&quot;)
      private Storage storage;
  
      public long getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getFormat() {
          return format;
      }
  
      public void setFormat(String format) {
          this.format = format;
      }
  
  
      public long getSize_file() {
          return size_file;
      }
  
      public void setSize_file(int size_file) {
          this.size_file = size_file;
      }
  
      public Storage getStorage() {
          return storage;
      }
  
      public void setStorage(Storage storage) {
          this.storage = storage;
      }
  
      @Override
      public String toString() {
          return &quot;File{&quot; +
                  &quot;id=&quot; + id +
                  &quot;, name='&quot; + name + '\'' +
                  &quot;, format='&quot; + format + '\'' +
                  &quot;, size_file=&quot; + size_file +
                  &quot;, storage=&quot; + storage +
                  '}';
      }
  </code></pre>
  <pre><code>CREATE TABLE FILE_STORAGE(
      ID NUMBER NOT NULL ENABLE,
      CONSTRAINT FILE_PK PRIMARY KEY (ID),
      NAME NVARCHAR2(50) NOT NULL,
      FORMAT NVARCHAR2(50) NOT NULL,
      SIZE_FILE NUMBER NOT NULL,
      STORAGE NUMBER NULL,
      CONSTRAINT STORAGE_ID_FK FOREIGN KEY (STORAGE_ID) REFERENCES STORAGE(ID)
  );
  </code></pre>
  <pre><code>авг. 14, 2019 8:10:14 AM org.hibernate.Version logVersion
  INFO: HHH000412: Hibernate Core {5.4.1.Final}
  авг. 14, 2019 8:10:21 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager &lt;clinit&gt;
  INFO: HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
  авг. 14, 2019 8:10:23 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
  авг. 14, 2019 8:10:25 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
  INFO: HHH10001005: using driver [oracle.jdbc.driver.OracleDriver] at URL [jdbc:oracle:thin:@gromcode-lessons.chrtxxrhorjs.us-east-2.rds.amazonaws.com:1521:ORCL]
  авг. 14, 2019 8:10:25 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
  INFO: HHH10001001: Connection properties: {password=****, user=main}
  авг. 14, 2019 8:10:25 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
  INFO: HHH10001003: Autocommit mode: false
  авг. 14, 2019 8:10:25 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections &lt;init&gt;
  INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
  авг. 14, 2019 8:10:30 AM org.hibernate.dialect.Dialect &lt;init&gt;
  INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
  авг. 14, 2019 8:10:37 AM org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService
  INFO: HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
  Exception in thread &quot;main&quot; java.lang.ClassCastException: class java.lang.Long cannot be cast to class java.lang.Integer (java.lang.Long and java.lang.Integer are in module java.base of loader 'bootstrap')
      at org.hibernate.type.descriptor.java.IntegerTypeDescriptor.unwrap(IntegerTypeDescriptor.java:19)
      at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$1.doBind(IntegerTypeDescriptor.java:46)
      at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:74)
      at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:276)
      at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:271)
      at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:53)
      at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:645)
      at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:2006)
      at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1920)
      at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1898)
      at org.hibernate.loader.Loader.doQuery(Loader.java:937)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:340)
      at org.hibernate.loader.Loader.doList(Loader.java:2695)
      at org.hibernate.loader.Loader.doList(Loader.java:2678)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2512)
      at org.hibernate.loader.Loader.list(Loader.java:2507)
      at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:504)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:396)
      at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:224)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1538)
      at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1561)
      at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1529)
      at org.hibernate.query.Query.getResultList(Query.java:168)
      at com.lesson3.hometask.DAO.DAO.listFileSize(DAO.java:276)
      at com.lesson3.hometask.validate.Validate.checkMaxSizeInStorage(Validate.java:36)
      at com.lesson3.hometask.Service.Service.put(Service.java:43)
      at com.lesson3.hometask.Controller.Controller.put(Controller.java:23)
      at com.lesson3.hometask.Demo.Demo.main(Demo.java:27)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:567)
      at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
  </code></pre>