我想在使用最新 Grails 里程碑 (2.0.0.M1) 开发的应用程序中使用 JPA 域模型。 JPA 域类位于应用程序的 src\java
目录中。
基于 this blog post它描述了如何在 Grails 应用程序中使用现有的 JPA 域模型,我创建了 grails-app/conf/hibernate/hibernate.cfg.xml
并带有我的 JPA 注释类列表。
如果有人无聊到想自己运行应用程序,可以使用 here .当您运行应用程序时,启动时会出现以下错误
Error 2011-08-04 23:28:19,777 [Thread-8] ERROR context.GrailsContextLoader - Error executing bootstraps: Error creati
ng bean with name 'grailsDomainClassMappingContext': Instantiation of bean failed; nested exception is org.springframewo
rk.beans.BeanInstantiationException: Could not instantiate bean class [org.codehaus.groovy.grails.domain.GrailsDomainCla
ssMappingContext]: Constructor threw exception; nested exception is java.lang.NullPointerException
Line | Method
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 138 | run in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 662 | run . . in java.lang.Thread
Caused by BeanInstantiationException: Could not instantiate bean class [org.codehaus.groovy.grails.domain.GrailsDomainCl
assMappingContext]: Constructor threw exception; nested exception is java.lang.NullPointerException
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 138 | run in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 662 | run . . in java.lang.Thread
Caused by NullPointerException: null
->> 123 | addPersistentEntityInternal in org.grails.datastore.mapping.model.AbstractMappingContext
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 115 | addPersistentEntity in ''
| 127 | addPersistentEntityInternal in ''
| 115 | addPersistentEntity in ''
| 127 | addPersistentEntityInternal in ''
| 115 | addPersistentEntity in ''
| 303 | innerRun in java.util.concurrent.FutureTask$Sync
| 138 | run in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 662 | run . . in java.lang.Thread
奇怪的是,这个问题似乎只由与其他域类有关系的域类触发。如果您删除除了 SystemProperty
之外的所有域类(不引用其他域类),应用程序将正常启动。
最佳答案
尝试使用 META-INF/persistence.xml
( example )(我不知道它到底放在哪里,但它最终应该去 WEB-INF/META-INF/persistence.xml
,并在那里包含你的 jar 文件(在 <jar-file>
元素中)。当然你需要所有相应的 Spring bean 类(例如 LocalEntityManagerFactoryBean
)
关于java - 在 Grails 中使用 JPA 域类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6355646/