hibernate - Grails/Hibernate不会在MySQL Linux上自动创建表

标签 hibernate grails

我在Windows本地主机上成功运行了Grails应用程序。然后,我将 war 部署到Linux上。整个应用程序正常运行,除了Hibernate(我相信)不希望在此创建任何表:

org.springframework.dao.InvalidDataAccessResourceUsageException:
   could not execute query;
   ...
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
   Table 'xxx.yyy' doesn't exist
   ...
(no other errors noticed)

手动创建所有表后,该应用程序即可正常运行。

问题是,如何使表自动创建? 就像应该的那样。

本地MySQL:
MySQL Ver 14.14 Distrib 5.5.28, for Win64 (x86)

服务器的MySQL:
mysql  Ver 14.14 Distrib 5.5.24, for debian-linux-gnu (x86_64) using readline 6.2

文件/etc/tomcat7/context.xml:
    <Resource name="jdbc/XXX" auth="Container"
          type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://localhost:3306/xxx"
          username="xxx" password="xxx" maxActive="20" maxIdle="10"
          removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"
          maxWait="-1"/>

最佳答案

在您的休眠配置文件中将休眠属性hbm2ddl.auto设置为“创建”。

关于hibernate - Grails/Hibernate不会在MySQL Linux上自动创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13670959/

相关文章:

hibernate - javax.persistence.criteria 和 org.hibernate.criterion 包之间有什么区别?

hibernate - 何时使用 Hibernate 投影?

java - MVC 模板项目看不到 hibernate.cfg.xml

java - 在RegexRequestMatcher中允许查询字符串

json - 如何在Grails中使用正确的内容类型呈现任意JSON?

hibernate - 如何在 Criteria Query 中使用 MAP 的键?

mysql - 使用 setMaxResults 和 native 查询创建的 SQL 查询不正确

grails - 具有多个多对多关联的GORM 'where criteria'

spring - Spring Security如何在Grails中调用remoteFunction时重定向到登录

grails - "GrailsDomainException: Identity property not found, but required in domain class"仅在 WebSphere 7 上