Grails忽略了hibernate.cfg.xml

时间:2010-09-28 14:08:24

标签: hibernate grails hibernate.cfg.xml

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

我阅读了插件文档,发现可以将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数据源定义如下。

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

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

这条线让我感到困惑

  

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

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