gpt4 book ai didi

hibernate - Grails 忽略 hibernate.cfg.xml

转载 作者:行者123 更新时间:2023-12-02 23:37:38 25 4
gpt4 key购买 nike

实际上,我在两个 tomcat 实例上部署了 grails 应用程序。现在我遇到了一个问题。我的 Quartz 作业需要集群。

我阅读了插件文档,发现可以将 Quartz 作业与数据库结合起来进行集群。

因此,我必须在我的 grails 应用程序中创建一个 hibernate 映射('grails-app/conf/hibernate/hibernate.cfg.xml')。

<?xml version='1.0' encoding='UTF-8'?>

<session-factory>
<mapping resource='Quartz.hbm.xml'/>
</session-factory>

然后我还创建了一个Quartz.hbm.xml。这将为 Quartz 插件创建表。

当我启动我的应用程序时,grails 似乎没有使用 hibernate.cfg.xml 并且没有创建表。

我的想法是问题出在我下面的 Spring Datasource 定义上。

import org.apache.commons.dbcp.BasicDataSource
import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH

// Place your Spring DSL code here
beans = {
dataSource(BasicDataSource) { bean ->
bean.destroyMethod = 'close'
def ds = CH.config.dataSource
// required attributes
if(ds.driverClassName == "com.mysql.jdbc.Driver") {
url = ds.url
username = ds.username
password = ds.password
driverClassName = ds.driverClassName
// optional attributes
minEvictableIdleTimeMillis = 1000 * 60 * 30
timeBetweenEvictionRunsMillis = 1000 * 60 * 30
numTestsPerEvictionRun = 3
testOnBorrow = true
testWhileIdle = false
testOnReturn = false
initialSize = 2
minIdle = 1
maxIdle = 4
validationQuery = "SELECT NOW()"
} else {
url = ds.url
username = ds.username
password = ds.password
driverClassName = ds.driverClassName
}
}
}

现在我有了 hibernate 日志的输出。看起来该文件将被解释。但是解析之后发生了什么?日志中没有任何异常。

2010-09-29 11:30:39,852 [main] DEBUG org.hibernate.util.DTDEntityResolver  - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd]
2010-09-29 11:30:39,852 [main] DEBUG org.hibernate.util.DTDEntityResolver - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd]
2010-09-29 11:30:39,852 [main] DEBUG org.hibernate.util.DTDEntityResolver - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
2010-09-29 11:30:39,852 [main] DEBUG org.hibernate.util.DTDEntityResolver - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
2010-09-29 11:30:39,852 [main] DEBUG org.hibernate.util.DTDEntityResolver - located [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd] in classpath
2010-09-29 11:30:39,852 [main] DEBUG org.hibernate.util.DTDEntityResolver - located [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd] in classpath
2010-09-29 11:30:39,868 [main] DEBUG org.hibernate.cfg.AnnotationConfiguration - null <- org.dom4j.tree.DefaultAttribute@1374ffd [Attribute: name resource value "Quartz.hbm.xml"]
2010-09-29 11:30:39,868 [main] DEBUG org.hibernate.cfg.AnnotationConfiguration - null <- org.dom4j.tree.DefaultAttribute@1374ffd [Attribute: name resource value "Quartz.hbm.xml"]
2010-09-29 11:30:39,868 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : Quartz.hbm.xml
2010-09-29 11:30:39,868 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : Quartz.hbm.xml
2010-09-29 11:30:39,884 [main] DEBUG org.hibernate.util.DTDEntityResolver - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]
2010-09-29 11:30:39,884 [main] DEBUG org.hibernate.util.DTDEntityResolver - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]
2010-09-29 11:30:39,884 [main] DEBUG org.hibernate.util.DTDEntityResolver - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
2010-09-29 11:30:39,884 [main] DEBUG org.hibernate.util.DTDEntityResolver - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
2010-09-29 11:30:39,884 [main] DEBUG org.hibernate.util.DTDEntityResolver - located [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
2010-09-29 11:30:39,884 [main] DEBUG org.hibernate.util.DTDEntityResolver - located [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
2010-09-29 11:30:39,930 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
2010-09-29 11:30:39,930 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null

有什么想法吗?

最佳答案

这句话让我感到困惑

Then I also created a Quartz.hbm.xml. This one creates the tables for the Quartz Plugin.

我相信您应该使用特定于您的数据库的 src/templates/sql 目录中提供的映射文件。

关于hibernate - Grails 忽略 hibernate.cfg.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3813622/

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