简体   繁体   中英

Hibernate gives 'table is not mapped' Exception

I configured package which contains pojo entity class which defined tables.

However, I see errors from below query

public interface TargetRepository extends CrudRepository<TargetEntity, String> {
    @Query("SELECT a, b FROM target_table")
    public List<Object> selectTargets();
}

org.hibernate.hql.internal.ast.QuerySyntaxException: target_table is not mapped

How can I fix it?

Your query is just wrong. You don't specify name of table as in SQL database. You specify name of table as name of entity in your application. So, it should be something like:

@Query("select te from TargetEntity te")
List<TargetEntity> selectTargets();

Also, as far as I see, your query is supposed to fetch all targets. Therefore, you could just define method:

List<TargetEntity> findAll();

and voila! Magic! It will fetch all records from your table_target table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM