Using JPA domain classes in Grails

Viewed 2436

I want to use a JPA domain model in an application developed using the latest Grails milestone (2.0.0.M1). The JPA domain classes are in the src\java directory of the application.

Based on this blog post which describes how to use an existing JPA domain model in a Grails app, I created grails-app/conf/hibernate/hibernate.cfg.xml with a list of my JPA-annotated classes.

In case anyone is bored enough to want to run the app themselves, it's available here. When you run the application the following error occurs on startup

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

Curiously, the problem only seems to be triggered by domain classes that have relationships with other domain classes. If you remove all domain classes except SystemProperty (which doesn't refer to other domain classes), the app starts without error.

3 Answers
Related