この内容は古いバージョンです。最新バージョンを表示するには、戻るボタンを押してください。
バージョン:4
ページ更新者:atom
更新日時:2026-05-15 03:52:15

タイトル: org.hibernate.hql.internal.ast.QuerySyntaxException: table_name is not mapped
SEOタイトル: Hibernate QuerySyntaxException: table_name is not mapped 対処

この記事の要点
  • Hibernate の QuerySyntaxException: table_name is not mapped エラー
  • 原因: @Query 内にテーブル名(DB 上の名前)を書いている
  • 対処: テーブル名ではなく Entity クラス名を書く(JPQL は Entity 名ベース)
  • 例: テーブル TestTable でも JPQL では FROM TestEntity

 

エラー内容

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

 

発生条件/原因

@Queryアノテーション内のテーブル名が正しくないのが原因。

 

対処法

@Query内に書くテーブル名は実際のテーブル名ではなく、Entity名を指定する点に注意。

以下の例を参照。(テーブル名はTestTable)

@Repository

public interface TestTableRepository extends JpaRepository<TestTable, String>{

@Query("FROM TestTable WHERE ID = :id")

TestTable findById(@Param("id") String id);

}