thinker thinker - 5 months ago 38
Java Question

Hibernate says: table is not mapped -is it true?

A database entity (a database contains table


@Table(name = "topics")
public class Topic { ...

service method:

String queryString = "SELECT id FROM topics WHERE topic_name='" + topic_name + "'";
logger.debug(queryString); //SELECT id FROM topics WHERE topic_name='Chemistry'
Query query = session.createQuery(queryString); //an error is on this line

I get the error:

org.hibernate.hql.internal.ast.QuerySyntaxException: topics is not

What is wrong with entity mapping?


Your query should be like this

String queryString = "SELECT id FROM Topic WHERE topic_name='" + topic_name + "'"; 

as your entity class is defined to be Topic.