【问题标题】:Hibernate: table thingsdb.Things doesn't exist休眠:表 thingsdb.Things 不存在
【发布时间】:2014-04-01 20:10:09
【问题描述】:

我正在尝试使用 Hibernate 从数据库中检索我的所有 Things,但出现此错误:

Table 'thingsdb.Things' doesn't exist org.hibernate.exception.SQLGrammarException: could not execute query

数据库中的表实际上命名为things,而不是Things

我正在执行的查询如下:

List<Thing> listofthings = session.createQuery(" from Thing thing").list();

还有休眠的xml:

<hibernate-configuration>
    <session-factory>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost/mythings</property>
        <property name="connection.username">root</property>
        <property name="connection.password"></property>
        <property name="connection.pool_size">5</property>
        <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
        <property name="show_sql">true</property>
        <mapping class="mythings.Thing" />
    </session-factory>
</hibernate-configuration>

我试图寻找解决方案,但没有找到。我是 Hibernate 的新手,所以我真的不知道要查找什么或在哪里查找。

【问题讨论】:

    标签: java hibernate web-applications


    【解决方案1】:

    您需要设置表的名称,否则它会尝试使用默认名称(即类名)构建查询:

    @Entity
    @Table(name="thing")
    public class Thing {
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 2014-03-15
      • 1970-01-01
      • 2011-05-28
      • 1970-01-01
      • 1970-01-01
      • 2016-05-16
      • 1970-01-01
      • 2021-04-14
      相关资源
      最近更新 更多