0

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.

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 ? 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?

org.hibernate.QueryException:could not resolve the property statusCode of -----WebsiteAvailability---

In the hibernate mapping file I have checked for case sensitivity.Still getting could not resolve property exception

5
  • You're getting exceptions, but we don't seem to be. What's the mystery exception? (Please show the exact text of the exception, and the output of select version() on your PostgreSQL install) Commented May 22, 2013 at 10:26
  • First of all what is the exception you are getting? Post the stacktrace Commented May 22, 2013 at 10:26
  • What is the exception? Commented May 22, 2013 at 10:26
  • please add the completet stack trace. however your resultset should be a list of WebsiteAvailability. Commented May 22, 2013 at 10:27
  • in select query it is taking "?" as it is.It is not taking selUrl value which I have passed from servlet.In this program I tried to print selUrl and it is giving correct supplied value.But ? is not taking selUrl value Commented May 22, 2013 at 10:31

1 Answer 1

1

You're trying to execute an HQL query, working on Hibernate entities, as a SQL query, using JDBC statements. That doesn't make sense. HQL queries are executed by the Hibernate Session. Not by 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).

Read the documentation about HQL query execution. You'll also have to fix your query, because it doesn't seem right. It contains w.statusCode and also w.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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.