【问题标题】:Grails or Hibernate not creating missing tableGrails 或 Hibernate 不创建丢失的表
【发布时间】:2012-07-12 01:18:16
【问题描述】:

我是 Grails 的新手,所以请原谅我的无知 - 如果其他信息有帮助,我会尽力将其发布。

我创建了一个单一的域模型类ToolKitComponent,它被定义为:

class ToolKitComponent {
    String componentName
    String componentVersion
    int componentDownloads
    Date compnentLastUpdate

    static constraints = {

    }
}

我有一个控制器,我只是想通过持久化一个示例来测试 ORM,所以这里是控制器的内容:

def index() { 
        ToolKitComponent i = new ToolKitComponent()
        i.setComponentName("TestComponent")
        i.setComponentVersion("v1.10")
        i.setComponentDownloads(1)
        i.setCompnentLastUpdate(new Date())
        i.save()
}

我已经安装了 MySql 数据库插件并将我的 DataSource.groovy 更新为:

dataSource {
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
    loggingSql = true
}

// other settings

environments {
    development {
        dataSource {
            String dbCreate = "create"
            String url = "jdbc:mysql://localhost/testDataBase"
            String username = "myUser"
            String password = "myPass"
        }
    }
}

我已经创建了数据库 testDataBase 并将所有权限授予用户名。

当我运行应用程序时,我得到:

Hibernate: insert into tool_kit_component (version, compnent_last_update, component_downloads, component_name, component_version) values (?, ?, ?, ?, ?)
| Error 2012-07-11 20:01:52,727 [http-bio-8080-exec-2] ERROR util.JDBCExceptionReporter  - Table "TOOL_KIT_COMPONENT" not found; SQL statement:
insert into tool_kit_component (version, compnent_last_update, component_downloads, component_name, component_version) values (?, ?, ?, ?, ?) [42102-164]
| Error 2012-07-11 20:01:52,752 [http-bio-8080-exec-2] ERROR errors.GrailsExceptionResolver  - JdbcSQLException occurred when processing request: [GET] /TestProject/
Table "TOOL_KIT_COMPONENT" not found; SQL statement:
insert into tool_kit_component (version, compnent_last_update, component_downloads, component_name, component_version) values (?, ?, ?, ?, ?) [42102-164]. Stacktrace follows:
Message: Table "TOOL_KIT_COMPONENT" not found; SQL statement:
insert into tool_kit_component (version, compnent_last_update, component_downloads, component_name, component_version) values (?, ?, ?, ?, ?) [42102-164]
    Line | Method
->>  329 | getJdbcSQLException in org.h2.message.DbException
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    169 | get                 in     ''
|    146 | get . . . . . . . . in     ''
|   4753 | readTableOrView     in org.h2.command.Parser
|   4731 | readTableOrView . . in     ''
|    954 | parseInsert         in     ''
|    375 | parsePrepared . . . in     ''
|    279 | parse               in     ''
|    251 | parse . . . . . . . in     ''
|    217 | prepareCommand      in     ''
|    415 | prepareLocal . . .  in org.h2.engine.Session
|    364 | prepareCommand      in     ''
|   1121 | prepareCommand . .  in org.h2.jdbc.JdbcConnection
|     71 | <init>              in org.h2.jdbc.JdbcPreparedStatement
|    267 | prepareStatement .  in org.h2.jdbc.JdbcConnection
|   1051 | prepareStatement    in     ''
|    508 | prepareStatement .  in org.apache.commons.dbcp.DelegatingConnection
|    400 | prepareStatement    in org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
|     11 | index . . . . . . . in TestProject.HomeController
|   1110 | runWorker           in java.util.concurrent.ThreadPoolExecutor
|    603 | run . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run                 in java.lang.Thread

我正在使用 Grails 2.0.4。

感谢任何帮助!

【问题讨论】:

    标签: mysql grails grails-orm grails-domain-class grails-2.0


    【解决方案1】:

    去掉数据源定义中的String

    environments {
        development {
            dataSource {
                dbCreate = "create"
                url = "jdbc:mysql://localhost/testDataBase"
                username = "myUser"
                password = "myPass"
    
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-12-29
      • 2015-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-05
      • 2016-07-07
      • 2011-11-17
      • 2012-05-09
      相关资源
      最近更新 更多