0

对于最简单的查询,我收到以下错误:

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>

ThreadLocalSessionContextorg.hibernate.context.internalHibernate 4.x-hibernate-core-4.2.6.Final.jar

Hibernate 上的其他一切工作正常。但是,我无法运行查询。

我错过了什么?

感谢帮助。

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

编辑:

<table_name>被定义为一个实体,hibernate.cfg.xml除了HQL 之外的所有内容——包括更新<table_name>都没有错误。

4

2 回答 2

0

我想到了两种可能性

  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].
    
于 2014-04-13T19:53:32.907 回答
0

错误应该主要来自query itself. 您应该尝试确保Entity您正在执行请求class的名称与SQL table与其关联的名称完全相同。

于 2014-08-25T00:11:20.690 回答