gpt4 book ai didi

mongodb - 将MongoDB和Hibernate结合使用的Grails 3.3.0 M1和3.3.0 M2失败

转载 作者:行者123 更新时间:2023-12-02 15:47:52 24 4
gpt4 key购买 nike

步骤1:使用命令创建应用

grails create-app test

步骤2:建立网域
grails create-domain-class test

第三步:配置build.gradle
compile 'org.grails.plugins:mongodb'

步骤4:配置application.yml
grails:
mongodb:
host: "localhost"
port: 27017
username: ""
password: ""
databaseName: "test"
environments:
development:
dataSource:
dbCreate: none
url:jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
logSql: true

步骤5:在Test.groovy中使用mapWith
static mapWith="mongo"

步骤6:在 bootstrap 中进行查询测试
println Test.findAll()

Stop7:运行grails应用
grails run-app

错误是:
 org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not prepare statement; bad SQL grammar [select this_.id as id1_0_0_, this_.version as version2_0_0_ from test this_]; nested exception is org.h2.jdbc.JdbcSQLException: Table "TEST" not found; SQL statement:
select this_.id as id1_0_0_, this_.version as version2_0_0_ from test this_ [42102-194]
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.grails.orm.hibernate.GrailsHibernateTemplate.convertJdbcAccessException(GrailsHibernateTemplate.java:723)
at org.grails.orm.hibernate.GrailsHibernateTemplate.convertHibernateAccessException(GrailsHibernateTemplate.java:711)
at org.grails.orm.hibernate.GrailsHibernateTemplate.doExecute(GrailsHibernateTemplate.java:302)
at org.grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:242)
at org.grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:116)
at org.grails.orm.hibernate.HibernateGormStaticApi.list(HibernateGormStaticApi.groovy:74)
at org.grails.datastore.gorm.GormStaticApi.findAll(GormStaticApi.groovy:579)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.findAll(GormEntity.groovy:671)
at org.grails.datastore.gorm.GormEntity$Trait$Helper$findAll$0.call(Unknown Source)

使用其他版本:
  • 3.2.3是可以的
  • 3.2.5是可以的
  • 3.2.9还可以

  • 我的代码是:
    the demo in github

    3.3.0.M1和3.3.0.M2有什么变化?

    最佳答案

    grails:
    mongodb:
    host: "localhost"
    port: 27017
    username: ""
    password: ""
    databaseName: "test"

    environments:
    development:
    dataSource:
    dbCreate: none
    url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    logSql: true
    test:
    dataSource:
    dbCreate: update
    url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    production:
    dataSource:
    dbCreate: none
    url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    properties:
    jmxEnabled: true
    initialSize: 5
    maxActive: 50
    minIdle: 5
    maxIdle: 25
    maxWait: 10000
    maxAge: 600000
    timeBetweenEvictionRunsMillis: 5000
    minEvictableIdleTimeMillis: 60000
    validationQuery: SELECT 1
    validationQueryTimeout: 3
    validationInterval: 15000
    testOnBorrow: true
    testWhileIdle: true
    testOnReturn: false
    jdbcInterceptors: ConnectionState
    defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED

    将这些行替换为此
    environments:
    development:
    grails:
    mongodb:
    host: "localhost"
    port: 27017
    username: ""
    password: ""
    databaseName: "test"
    test:
    mongodb:
    host: "localhost"
    port: 27017
    username: ""
    password: ""
    databaseName: "test"
    production:
    grails:
    mongodb:
    host: "localhost"
    port: 27017
    username: ""
    password: ""
    databaseName: "test"
    properties:
    jmxEnabled: true
    initialSize: 5
    maxActive: 50
    minIdle: 5
    maxIdle: 25
    maxWait: 10000
    maxAge: 600000
    timeBetweenEvictionRunsMillis: 5000
    minEvictableIdleTimeMillis: 60000
    validationQuery: SELECT 1
    validationQueryTimeout: 3
    validationInterval: 15000
    testOnBorrow: true
    testWhileIdle: true
    testOnReturn: false
    jdbcInterceptors: ConnectionState
    defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED

    关于mongodb - 将MongoDB和Hibernate结合使用的Grails 3.3.0 M1和3.3.0 M2失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44426001/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com