I got this exception when i try to get the list using NamedQuery:
org.hibernate.exception.SQLGrammarException: could not execute query
Below I mentioned code:
Entity Class Code:
@Table(name = "tbl_users")
@XmlRootElement
@NamedQueries({@NamedQuery(name = "TblUsers.findAll", query = "SELECT t FROM TblUsers t")});
DAO implement Code:
org.hibernate.Query query = session.getNamedQuery("TblUsers.findAll");
List list = query.list();
Please provide solution for this exception.
Was facing same issue for a while and figured out that the problem was due to the Table name being different from the class(or Entity) name in the database. Added the @Table(name = actual_table_name) annotation and it worked.
Get the SQL query that Hibernate is generating (using hibernate.show_sql or, preferably, Hibernate's SQL logging), and execute it against the database yourself. That will most likely help steer you in the right direction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With