iUbaid
iUbaid

Reputation: 321

Hibernate auto table generation from domain class is not working in Grails with MySQL

All the domain classes are being mapped as tables in MySQL instead of one domain class named USER (Name of the table is changed to db_user in mapping to avoid keyword violations) as shown belowenter image description here:

And application keeps showing error on startup :

Caused by: java.sql.SQLSyntaxErrorException: Table 'umm.db_user' doesn't exist

Versions of stack:

| Grails Version: 3.2.3

| Groovy Version: 2.4.7

| JVM Version: 1.8.0_242

| Gradle: 3.0

| MySQL: 8.0.26-cluster

| Hibernate: 5.1.1.Final

application.groovy

application.groovy

application.yml

enter image description here

Logs:

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

Upvotes: 0

Views: 301

Answers (1)

Sikander
Sikander

Reputation: 862

Do three things,

  1. Change dialect to

    org.hibernate.dialect.MySQL8Dialect

  2. and/update mysql driver dependency

    mysql:mysql-connector-java:8.0.17

  3. Make sure you are using the correct type in configs (Holders.config.ProfilePictureType) (longtext, maybe)

Upvotes: 1

Related Questions