我的第一个 grails 应用程序有问题。我试图修改我的休眠文件一百次,但我仍然得到这个异常:
| Error 2012-12-03 13:24:23,190 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error executing bootstraps:
Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org
.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve
reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframewor
k.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed;
nested exception is org.hibernate.InvalidMappingException: Could not parse mapping document from resource user.hbm.xml
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exceptio
n is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot
resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.spring
framework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method
failed; nested exception is org.hibernate.InvalidMappingException: Could not parse mapping document from resource user.
hbm.xml
Line | Method
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 's
essionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanC
reationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is
org.hibernate.InvalidMappingException: Could not parse mapping document from resource user.hbm.xml
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; neste
d exception is org.hibernate.InvalidMappingException: Could not parse mapping document from resource user.hbm.xml
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
Caused by InvalidMappingException: Could not parse mapping document from resource user.hbm.xml
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
Caused by DuplicateMappingException: Duplicate class/entity mapping santrain.User
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
用户.groovy:
package test
class User {
Integer id
String f1
String f2
static constraints = {
}
}
休眠.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
'-//Hibernate/Hibernate Configuration DTD 3.0//EN'
'http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd'>
<hibernate-configuration>
<session-factory>
<mapping resource='user.hbm.xml'/>
</session-factory>
</hibernate-configuration>
编辑:当我写 - >一切正常,所以错误必须在user.hbm.xml中的任何地方......
用户.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="test">
<class name="test.User" table="test_user">
<id name="id" column="id" type="java.lang.Integer" />
<property column="f1" name="f1" type="java.lang.String" />
<property column="f2" name="f2" type="java.lang.String" />
</class>
</hibernate-mapping>
数据源.groovy
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
username = "testuser"
password = "testpass"
}
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"
url = "jdbc:mysql://localhost:3306/testdb?autoreconnect=true"
}
}
...
任何帮助表示赞赏,谢谢!