简体   繁体   English

使用Hibernate从数据库访问值时获取异常

[英]Getting exception while accessing values from data base using hibernate

I have two tables website_availability and status_codes.And these have foriegn key relation between them.status_codes is parent table.I am using hibernate.I need "list" of values from these tables after joining.I am following this code. 我有两个表website_availability和status_codes。它们之间具有前键关系。status_codes是父表。我正在使用hibernate。加入后,我需要从这些表中“列出”值。我正在遵循此代码。

List<WebsiteAvailability>list=new ArrayList<WebsiteAvailability>
String selquery="select w.statusCode,w.updateTime,w.statusCodes.statusCodeValue from  WebsiteAvailability w,StatusCodes s where w.statusCodes.statusCode=s.statusCode and w.url=?";
//here hibernate generates the POJO classes and these are having foriegn key relation so     WebsiteAvailability is having private StatusCodes statusCodes.So I am accessing statuscodevalue of statuscodes table using w.statusCodes.statusCodeValue.
PreparedStatement ps=con.prepareStatement(selquery);
ps.setString(1,selUrl);
rs=ps.executeQuery();
while(rs.next())
{
list.add(new     WebsiteAvailability(rs.getString("statusCode"),rs.getTimestamp("updateTime"),rs.getString("statusCodeValue")));
}
return list;

}

First of all can I use resultset with hibernate.Is there any alternative for this.Because as I am using ? 首先我可以将结果集与hibernate一起使用吗?是否有其他选择。因为我正在使用? placeholder I should use preparedstatement for setString().And executeQuery() to get the list.I need list of values how can i get.Am getting empty list.What is the error? 占位符我应该对setString()使用preparestatement。和executeQuery()获取列表。我需要如何获取值列表。正在获取空列表。错误是什么?

org.hibernate.QueryException:could not resolve the property statusCode of -----WebsiteAvailability--- org.hibernate.QueryException:无法解析----- WebsiteAvailability ---的属性statusCode

In the hibernate mapping file I have checked for case sensitivity.Still getting could not resolve property exception 在休眠映射文件中,我检查了是否区分大小写。仍然无法解决属性异常

You're trying to execute an HQL query, working on Hibernate entities, as a SQL query, using JDBC statements. 您正在尝试使用JDBC语句以SQL查询的形式在Hibernate实体上执行HQL查询。 That doesn't make sense. 那没有道理。 HQL queries are executed by the Hibernate Session. HQL查询由休眠会话执行。 Not by JDBC. 不是通过JDBC。 If you're using Hibernate, you don't need JDBC anymore (except maybe in some corner cases when you need raw JDBC performance, like batches). 如果您使用的是Hibernate,则不再需要JDBC(除非在某些极端情况下,当您需要原始JDBC性能(例如批处理)时)。

Read the documentation about HQL query execution . 阅读有关HQL查询执行的文档。 You'll also have to fix your query, because it doesn't seem right. 您还必须修复查询,因为它看起来不正确。 It contains w.statusCode and also w.statusCodes . 它包含w.statusCodew.statusCodes It also does a join using equality statements and selects from two entities, instead of simply using implicit or explicit joins. 它还使用相等性语句进行联接并从两个实体中进行选择,而不是简单地使用隐式或显式联接。 Those are also explained in the documentation . 文档中也对这些内容进行了说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM