thinker thinker - 15 days ago 6
Java Question

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

A database entity (a database contains table

topics
):

@Entity
@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
mapped


What is wrong with entity mapping?

Answer

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.

Comments