質問

最も単純なクエリに対して次のエラーが発生します。

org.hibernate.hql.internal.ast.QuerySyntaxException: <table_name> is not mapped [<query_string>]

hibernate.cfg.xml 私は財産を持っています。

<property name="current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</property>

ThreadLocalSessionContext いる org.hibernate.context.internalHibernate 4.x-hibernate-core-4.2.6.Final.jar.

Hibernate 上の他のすべては正常に動作しています。ただし、クエリを実行できません。

私には何が欠けているのでしょうか?

手伝ってくれてありがとう。

//=========================

編集:

<table_name> エンティティとして定義されます hibernate.cfg.xml そして すべて ただし、HQL -- の更新を含む <table_name> エラーなく動作しています。

役に立ちましたか?

解決

私の頭に浮かぶ可能性は2つあります

  1. HQL で参照している名前はエンティティではありません。たとえば、

    HQL は「Select testEntity from TestEntity testEntity」ですが、TestEntity という名前のエンティティ クラスが定義されていません

または

  1. TestEntity を定義しましたが、管理されていません。エンティティ内の他の操作は機能しているとのことですが、おそらく HQL で間違った名前を使用しているようです。ただし、エンティティが管理されていることを確認したい場合は、Hibernate デバッグ ログを有効にすると、管理対象クラスのリストを確認できる以下のような情報が表示されます。

    01:09:40,322 DEBUG HibernatePersistenceProvider:110 - Checking persistence-unit [name=persistence-unit_test, explicit-provider=org.hibernate.ejb.HibernatePersistence] against incoming persistence unit name [persistence-unit_demo]
    01:09:40,322 DEBUG ProviderChecker:106 - Persistence-unit [persistence-unit_demo] requested PersistenceProvider [org.hibernate.ejb.HibernatePersistence]
    01:09:40,322 DEBUG LogHelper:117 - PersistenceUnitInfo [
        name: persistence-unit_demo
        persistence provider classname: org.hibernate.ejb.HibernatePersistence
        classloader: null
        excludeUnlistedClasses: false
        JTA datasource: null
        Non JTA datasource: null
        Transaction type: RESOURCE_LOCAL
        PU root URL: file:/E:/Test/target/classes/
        Shared Cache Mode: null
        Validation Mode: null
        Jar files URLs []
        Managed classes names [
            com.test.model.TestEntity
    
        Mapping files names []
        Properties [
            hibernate.c3p0.timeout: 100
            hibernate.connection.autocommit: false
            hibernate.connection.driver_class: com.mysql.jdbc.Driver
            hibernate.c3p0.max_statements: 0
            hibernate.c3p0.max_size: 50
            hibernate.dialect: org.hibernate.dialect.MySQL5InnoDBDialect
            hibernate.c3p0.idle_test_period: 100
            hibernate.c3p0.min_size: 5
            hibernate.connection.username: XXXX
            hibernate.hbm2ddl.auto: update
            hibernate.c3p0.acquire_increment: 5
            hibernate.connection.url: jdbc:mysql://localhost:3306/test
            hibernate.connection.password: XXXX
            hibernate.show_sql: true
            hibernate.connection.provider_class: org.hibernate.connection.C3P0ConnectionProvider]
    01:09:40,337 DEBUG IntegratorServiceImpl:63 - Adding Integrator [org.hibernate.cfg.beanvalidation.BeanValidationIntegrator].
    01:09:40,353 DEBUG IntegratorServiceImpl:63 - Adding Integrator [org.hibernate.secure.spi.JaccIntegrator].
    

他のヒント

エラーの主な原因は次のとおりです。 query itself. 。名前を確認してみてください Entity リクエストを実行しているのは、の名前とまったく同じです class の名前とは異なります SQL table それに関連付けられています。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top