First of all move the Java code to a Java file. Never write a single line of Java code in JSP. The structure of a Java web app is servlets do the work (connect to the database, execute queries,...), JSPs display the results. When I started in 2004 that was already the best practice and it didn't change. For more information read this excellent article and this topic.
Then I feel it will be very easy for you to identify the root cause of the exception.
After you have refactored your code, it will probably also be much easier to post a SSCCE (Short, Self Contained, Correct/Compilable, Example) instead of a bunch of (irrelevant) code snippets. Together with a stack trace of the exception, it will be much easier for us to help you and determine what's causing your problem and propose a solution.
But based on the stack trace, it seems something is wrong with your query. Try qualifying all properties of the classes in your query, e.g.Here you can find more information about JPQL.
And here's another tip! You shouldnever concatenate a value (entered by a user) directly into your query. It's not only considered a bad practice, but also makes your code vulnerable to SQL injection attacks. You can find more info on SQL injection here. You should always (wherever possible) use a prepared statement. With JPQL, you can either choose between named parameters (as I used in the above example) or positional parameters. For more information about using parameters, have a look at the Parameters section of the Java Persistence WikiBook.
I thought I'd posted last night, but it did lock up, so must have vanished into the aether.
Anyway (apart from the bits Roel has noted), that HQL query is returning only the bookname, but you seem to want a List of Books. I don't think that'll be the cause of the immediate exception, but it will fall over later when it tries to cast String to Book.
Dave Tolls wrote:Anyway (apart from the bits Roel has noted), that HQL query is returning only the bookname, but you seem to want a List of Books. I don't think that'll be the cause of the immediate exception, but it will fall over later when it tries to cast String to Book.
That's indeed a valid remark. If you want to have a list of Books objects, you should change the SELECT part of your query toAnd another minor remark: according to the naming conventions, a class name should be a noun (e.g. Author and Book). And that makes more sense than using e.g. Books. When you retrieve one single object (book) from your database, your code looks like thisIt clearly indicates one single book, whereas the following code snippet might suggest it's not one book but a collection of books