当我想返回查询结果并放入列表时,我得到错误"java.lang.ClassCastException: classjava.lang.Long不能转换为类java.lang.整数(java.lang.Long和java.lang.整数在加载器'bootstrap'的模块java.base)"。我试图更改类型值,但错误没有消失。
Query query = session.createQuery("SELECT size_file FROM File WHERE storage.id =: storage_id", Number.class)
.setParameter("storage_id", storage.getId());
List<Number> list=(List<Number>)query.getResultList();
@Entity
@Table(name = "FILE_STORAGE")
public class File {
@Id
@Column(name = "ID")
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
@Column(name = "NAME")
private String name;
@Column(name = "FORMAT")
private String format;
@Column(name = "SIZE_FILE")
private int size_file;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "STORAGE_ID")
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 "File{" +
"id=" + id +
", name='" + name + '\'' +
", format='" + format + '\'' +
", size_file=" + size_file +
", storage=" + storage +
'}';
}
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)
);
авг. 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 <clinit>
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 <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
авг. 14, 2019 8:10:30 AM org.hibernate.dialect.Dialect <init>
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 "main" 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)
将long getId()更改为int getId();
在我的项目中,我有这样一个枚举: 我有这个代码: 我有个例外 myMap由数据库中的数据填充,知道它是SQL Server数据库,并且从数据库返回的myKey在数据库中是tinyint类型。 你能告诉我我做错了什么吗?谢谢 当做
当我想返回查询结果并放入列表时,我得到错误“java.lang.ClassCastException:类java.lang.Long不能被强制转换为类java.lang.Integer(java.lang.Long和java.lang.Integer在加载器'bootstrap'的模块java.base中)”。我尝试更改类型值,但错误没有消失。
错误 组织。springframework。果心转换ConverterNotFoundException:未找到能够从[java.lang.Integer]类型转换为[@org.springframework.data.jpa.repository.Query com.entity.CombHoldingRule]类型的转换器 实体类如下所示 存储库:-
我试图检索值从数据库显示在视图但我得到这个崩溃就在这里 致命异常:主进程:com。实例艾哈迈德。卡伦塔尔,PID:15975 com。谷歌。火力基地。数据库DatabaseException:未能转换java类型的值。在com上使用长字符串。谷歌。Androidgms。内部的zzear。zzb(未知来源)在com。谷歌。Androidgms。内部的zzear。zza(未知来源)在com上。谷歌。A
当我运行这个程序时,我得到了这个错误。我不知道怎么解决。请帮我找到它。 代码:
大家好,我的问题是我为android开发了一个应用程序,它使用json解析器从我的php Web服务中获取数据并将其显示在listview中,但当我运行该应用程序时,它显示了以下内容: 日志: 我的代码: 具有列表视图的活动并调用json解析器: Json解析器在这个我只改变了这一行BufferedReader=new BufferedReader(new InputStreamReader(is