gpt4 book ai didi

hibernate - 从表中全选 hibernate

转载 作者:行者123 更新时间:2023-12-04 05:31:53 26 4
gpt4 key购买 nike

所以我有以下代码:

Query query = session.createQuery("from Weather");
List<WeatherModel> list = query.list();
WeatherModel w = (WeatherModel) list.get(0);

我不会从Weather表中获取所有项目,但会不断出现以下错误:(第23行是我创建查询的地方)
java.lang.NullPointerException
at action.WeatherAction.validate(WeatherAction.java:23)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doBeforeInvocation(ValidationInterceptor.java:251)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)............

有什么问题?

最佳答案

Query query = session.createQuery("from Weather"); //You will get Weayher object
List<WeatherModel> list = query.list(); //You are accessing as list<WeatherModel>

他们都是不同的实体
Query query = session.createQuery("from Weather"); 

List<Weather> list = query.list();

Weather w = (Weather) list.get(0);

关于hibernate - 从表中全选 hibernate ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16372568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com