【问题标题】:Grails table not found error on SQL 2008 legacy tableSQL 2008 旧表上未找到 Grails 表错误
【发布时间】:2013-03-11 12:36:57
【问题描述】:

我正在尝试将一个新的 Grails 项目链接到一个预先存在的 SQL Server 2008 数据库,问题是当我尝试列出/更新或任何东西都不起作用时,我得到一个读取错误

未找到表“TEST_EXEC_QUEUE”; SQL语句:选择前10个this_.id为id0_0_,this_.Env为Env0_0_,this_.Priority为Priority0_0_,this_.State为State0_0_,this_.subSystem为subSystem0_0_,this_.system为system0_0_,this_.test_scenario_id为test7_0_0_ from test_exec_queue this_ [42102-164]

我的 datasource.groovy 文件是:-

dataSource {
    pooled = false
    driverClassName = "net.sourceforge.jtds.jdbc.Driver"
    dialect = "org.hibernate.dialect.SQLServerDialect"
    }

hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}


// environment specific settings
    development {
        dataSource {
            dbCreate = "update"
            url = "jdbc:jtds:sqlserver://UKSQL08;databaseName=Selenium"
        }
    }

域名文件如下,大家有什么想法吗...?

package testexecqueue

class TestExecQueueCheck {

    static constraints = {
        test_scenario_id(blank:false)
        myPriority()
        myState()
        myEnv()
        system()
        subSystem()
    }

    static mapping = {
        table "test_exec_queue"
        version false
        columns{

            test_scenario_id column:"test_scenario_id"
            myPriority column:"Priority"
            myState column:"State"
            myEnv column:"Env"
            system column:"system"
            subSystem column:"subSystem"
        }
    }

    Integer test_scenario_id
    Integer myPriority
    String myState
    String myEnv
    String system
    String subSystem
}

【问题讨论】:

    标签: sql grails legacy


    【解决方案1】:

    您的 TestExecQueueCheck 域中没有 id。将字段 test_scenario_id 重命名为 id。它应该可以解决问题。

    【讨论】:

    • 嗯,这似乎没有什么不同,我已经将所有名为 test_scenario_id 的变量更改为 id,清理并重新编译等,然后重新运行,我仍然遇到同样的问题......我假设你不是说把数据库字段改成id吧?
    • 我的意思是 Grails 域。我的建议应该改变结果:即使在您的 SQL 语句中,我们也可以看到它包含一个隐式列id(除了test_scenario_id)。 Grails 总是自动添加这样的列。重命名列后,检查新的“未找到”错误消息。是否包含不存在的列?
    • 现在说select top 10 this_.test_exec_queue_id as test1_0_0_, this_.Env as Env0_0_, this_.Priority as Priority0_0_, this_.State as State0_0_, this_.subSystem as subSystem0_0_, this_.system as system0_0_, this_.test_scenario_id as test7_0_0_ from test_exec_queue this_ [42102-164]
    • 现在的内容如下package testexecqueue class TestExecQueueCheck { static constraints = { testscenarioid() myPriority() myState() myEnv() system() subSystem() } static mapping = { table "test_exec_queue" version false columns{ id column:"test_exec_queue_id" testscenarioid column:"test_scenario_id" myPriority column:"Priority" myState column:"State" myEnv column:"Env" system column:"system" subSystem column:"subSystem" } } Integer testscenarioid Integer myPriority String myState String myEnv String system String subSystem }
    • 好的,如果可以重新生成表,请尝试将dbCreate 更改为"create"(并重新启动应用程序)并将生成的表模式与原始模式进行比较。如果它们不同,也许这就是原因,您必须通过对域的其他一些更改来使其一致。
    【解决方案2】:

    这可能不是答案,但我发现一旦我指定了一个实际帐户并移回 JDBC 连接,问题就消失了,所以它与 Windows 服务帐户/JTDS 有关,我还没有进一步调查...我使用 sqljdbc4 的数据源现在如下,并且工作正常...

    dataSource {
        pooled = true
        driverClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    }
    
    hibernate {
        cache.use_second_level_cache = true
        cache.use_query_cache = false
        cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
    }
    
    
    // environment specific settings
    environments {
        development {
            dataSource {
                dbCreate = 'update' // one of 'create', 'create-drop','update'
                url = "jdbc:sqlserver://localhost;database=TestDB"
        //      databaseName = "..."
            username = "test"
            password = "test"
                dialect = org.hibernate.dialect.SQLServerDialect
                //logSql = true
            }
        }
    

    【讨论】:

    • 另外补充一点,如果你想使用 Windows 身份验证,你需要确保将 jdbc jar 和 auth dll 都放在 lib 中,我只是在放置 jar 文件时遇到了问题在 lib 文件夹中,直到我添加了 auth dll 才开始工作,现在意味着我不需要指定用户帐户或密码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-06
    • 1970-01-01
    • 2015-07-27
    • 1970-01-01
    • 2012-02-13
    • 1970-01-01
    相关资源
    最近更新 更多