来自域 class 的 Hibernate 自动 table 生成在具有 MySQL 的 Grails 中不起作用
Hibernate auto table generation from domain class is not working in Grails with MySQL
所有域 class 都被映射为 MySQL 中的 table,而不是一个名为 USER[=53= 的域 class ](table的名称在映射中更改为db_user
以避免关键字违规)如下所示:
并且应用程序在启动时一直显示错误:
原因:java.sql.SQLSyntaxErrorException:Table 'umm.db_user' 不存在
堆栈版本:
| Grails 版本:3.2.3
| Groovy版本:2.4.7
| JVM 版本:1.8.0_242
| Gradle: 3.0
| MySQL: 8.0.26-集群
|休眠:5.1.1.Final
application.groovy
application.yml
日志:
2021-09-02 02:43:09.722 ERROR 26370 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : Table 'umm.db_user' doesn't exist
2021-09-02 02:43:09.783 ERROR 26370 --- [ main] grails.app.init.umm1.BootStrap : Exception occured in bootstrap:
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2122)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1905)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1881)
at org.hibernate.loader.Loader.doQuery(Loader.java:925)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342)
at org.hibernate.loader.Loader.doList(Loader.java:2622)
at org.hibernate.loader.Loader.doList(Loader.java:2605)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2434)
at org.hibernate.loader.Loader.list(Loader.java:2429)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1787)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363)
at org.grails.orm.hibernate.query.AbstractHibernateQuery.singleResultViaListCall(AbstractHibernateQuery.java:785)
at org.grails.orm.hibernate.query.AbstractHibernateQuery.singleResult(AbstractHibernateQuery.java:775)
Caused by: java.sql.SQLSyntaxErrorException: Table 'umm.db_user' doesn't exist
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:970) at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1020)
at sun.reflect.GeneratedMethodAccessor187.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498)
org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426) org.apache.tomcat.jdbc.pool.interceptor.StatementDecoratorInterceptor$StatementProxy.invoke(StatementDecoratorInterceptor.java:261)
at com.sun.proxy.$Proxy102.executeQuery(Unknown Source) org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70)
... 134 common frames omitted
Grails application running at http://localhost:9091/umm in environment: development
做好三件事,
将方言更改为
org.hibernate.dialect.MySQL8方言
and/update mysql 驱动依赖
mysql:mysql-连接器-java:8.0.17
确保您在配置中使用了正确的类型 (Holders.config.ProfilePictureType)(可能是长文本)
所有域 class 都被映射为 MySQL 中的 table,而不是一个名为 USER[=53= 的域 class ](table的名称在映射中更改为db_user
以避免关键字违规)如下所示
并且应用程序在启动时一直显示错误:
原因:java.sql.SQLSyntaxErrorException:Table 'umm.db_user' 不存在
堆栈版本:
| Grails 版本:3.2.3
| Groovy版本:2.4.7
| JVM 版本:1.8.0_242
| Gradle: 3.0
| MySQL: 8.0.26-集群
|休眠:5.1.1.Final
application.groovy
application.yml
日志:
2021-09-02 02:43:09.722 ERROR 26370 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : Table 'umm.db_user' doesn't exist
2021-09-02 02:43:09.783 ERROR 26370 --- [ main] grails.app.init.umm1.BootStrap : Exception occured in bootstrap:
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2122)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1905)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1881)
at org.hibernate.loader.Loader.doQuery(Loader.java:925)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342)
at org.hibernate.loader.Loader.doList(Loader.java:2622)
at org.hibernate.loader.Loader.doList(Loader.java:2605)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2434)
at org.hibernate.loader.Loader.list(Loader.java:2429)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1787)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363)
at org.grails.orm.hibernate.query.AbstractHibernateQuery.singleResultViaListCall(AbstractHibernateQuery.java:785)
at org.grails.orm.hibernate.query.AbstractHibernateQuery.singleResult(AbstractHibernateQuery.java:775)
Caused by: java.sql.SQLSyntaxErrorException: Table 'umm.db_user' doesn't exist
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:970) at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1020)
at sun.reflect.GeneratedMethodAccessor187.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498)
org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426) org.apache.tomcat.jdbc.pool.interceptor.StatementDecoratorInterceptor$StatementProxy.invoke(StatementDecoratorInterceptor.java:261)
at com.sun.proxy.$Proxy102.executeQuery(Unknown Source) org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70)
... 134 common frames omitted
Grails application running at http://localhost:9091/umm in environment: development
做好三件事,
将方言更改为
org.hibernate.dialect.MySQL8方言
and/update mysql 驱动依赖
mysql:mysql-连接器-java:8.0.17
确保您在配置中使用了正确的类型 (Holders.config.ProfilePictureType)(可能是长文本)