Abstract class not working with mongodb but working with hibernate
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
`abstract class BaseDomain {
```
static mapWith = "mongo"
transient springSecurityService
ObjectId id
def Long version
def Date createdOn
def Date updatedOn
def Long createdBy
def Long updatedBy
static constraints = {
version display:false
createdOn display:false
updatedOn display:false
createdBy display:false
updatedBy display:false
}
static mapping = {
sort updatedOn:'desc'
}
def beforeInsert = {
initDefaults()
return true
}
def beforeUpdate = {
def currentUser = springSecurityService.getCurrentUser()
updatedBy = currentUser ? currentUser.id : 0;
updatedOn = new Date();
}
def beforeValidate = {
initDefaults()
return true
}
def afterInsert = {
}
def afterUpdate = {
}
def afterDelete = {
}
def onLoad = {
}
def afterLoad = {
}
def dynamicProps = [:]
def propertyMissing(String name, value) { dynamicProps[name] = value }
def propertyMissing(String name) { dynamicProps[name] }
void initDefaults() {
def currentUser = springSecurityService?.getCurrentUser()
if (createdBy == null) {
createdBy = currentUser? currentUser.id : 0;
}
if (createdOn == null) {
createdOn = new Date();
}
if (updatedBy == null) {
updatedBy = currentUser? currentUser.id : 0;
}
if (updatedOn == null) {
updatedOn = new Date();
}
}
```
}`
This is my abstract class presented in src/groovy. if i am extending this class in my domain class i am getting the exception when i am trying to run the app. the same code is working with hibernate. but i am facing this issue with mongodb plugin.
`Error |
2016-05-30 13:49:15,331 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error initializing the application: Error creating bean with name 'instanceTagLibraryApi': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.codehaus.groovy.grails.plugins.web.api.TagLibraryApi.setGspTagLibraryLookup(org.codehaus.groovy.grails.web.pages.TagLibraryLookup); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gspTagLibraryLookup': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.codehaus.groovy.grails.web.mapping.LinkGenerator org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib.linkGenerator; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsLinkGenerator': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.grails.datastore.mapping.model.MappingContext org.codehaus.groovy.grails.web.mapping.DefaultLinkGenerator.mappingContext; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsDomainClassMappingContext': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.codehaus.groovy.grails.domain.GrailsDomainClassMappingContext]: Constructor threw exception; nested exception is java.lang.NullPointerException
Message: Error creating bean with name 'instanceTagLibraryApi': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.codehaus.groovy.grails.plugins.web.api.TagLibraryApi.setGspTagLibraryLookup(org.codehaus.groovy.grails.web.pages.TagLibraryLookup); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gspTagLibraryLookup': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.codehaus.groovy.grails.web.mapping.LinkGenerator org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib.linkGenerator; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsLinkGenerator': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.grails.datastore.mapping.model.MappingContext org.codehaus.groovy.grails.web.mapping.DefaultLinkGenerator.mappingContext; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsDomainClassMappingContext': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.codehaus.groovy.grails.domain.GrailsDomainClassMappingContext]: Constructor threw exception; nested exception is java.lang.NullPointerException
Line | Method
->> 262 | run in java.util.concurrent.FutureTask
---
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Could not autowire method: public void org.codehaus.groovy.grails.plugins.web.api.TagLibraryApi.setGspTagLibraryLookup(org.codehaus.groovy.grails.web.pages.TagLibraryLookup); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gspTagLibraryLookup': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.codehaus.groovy.grails.web.mapping.LinkGenerator org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib.linkGenerator; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsLinkGenerator': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.grails.datastore.mapping.model.MappingContext org.codehaus.groovy.grails.web.mapping.DefaultLinkGenerator.mappingContext; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsDomainClassMappingContext': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.codehaus.groovy.grails.domain.GrailsDomainClassMappingContext]: Constructor threw exception; nested exception is java.lang.NullPointerException
->> 262 | run in java.util.concurrent.FutureTask
---
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'gspTagLibraryLookup': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.codehaus.groovy.grails.web.mapping.LinkGenerator org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib.linkGenerator; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsLinkGenerator': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.grails.datastore.mapping.model.MappingContext org.codehaus.groovy.grails.web.mapping.DefaultLinkGenerator.mappingContext; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsDomainClassMappingContext': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.codehaus.groovy.grails.domain.GrailsDomainClassMappingContext]: Constructor threw exception; nested exception is java.lang.NullPointerException
->> 262 | run in java.util.concurrent.FutureTask
---
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.codehaus.groovy.grails.web.mapping.LinkGenerator org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib.linkGenerator; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsLinkGenerator': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.grails.datastore.mapping.model.MappingContext org.codehaus.groovy.grails.web.mapping.DefaultLinkGenerator.mappingContext; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsDomainClassMappingContext': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.codehaus.groovy.grails.domain.GrailsDomainClassMappingContext]: Constructor threw exception; nested exception is java.lang.NullPointerException
->> 262 | run in java.util.concurrent.FutureTask
---
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Could not autowire field: private org.codehaus.groovy.grails.web.mapping.LinkGenerator org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib.linkGenerator; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsLinkGenerator': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.grails.datastore.mapping.model.MappingContext org.codehaus.groovy.grails.web.mapping.DefaultLinkGenerator.mappingContext; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsDomainClassMappingContext': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.codehaus.groovy.grails.domain.GrailsDomainClassMappingContext]: Constructor threw exception; nested exception is java.lang.NullPointerException
->> 262 | run in java.util.concurrent.FutureTask
---
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'grailsLinkGenerator': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.grails.datastore.mapping.model.MappingContext org.codehaus.groovy.grails.web.mapping.DefaultLinkGenerator.mappingContext; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsDomainClassMappingContext': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.codehaus.groovy.grails.domain.GrailsDomainClassMappingContext]: Constructor threw exception; nested exception is java.lang.NullPointerException
->> 262 | run in java.util.concurrent.FutureTask
---
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Could not autowire field: private org.grails.datastore.mapping.model.MappingContext org.codehaus.groovy.grails.web.mapping.DefaultLinkGenerator.mappingContext; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsDomainClassMappingContext': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.codehaus.groovy.grails.domain.GrailsDomainClassMappingContext]: Constructor threw exception; nested exception is java.lang.NullPointerException
->> 262 | run in java.util.concurrent.FutureTask
---
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'grailsDomainClassMappingContext': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.codehaus.groovy.grails.domain.GrailsDomainClassMappingContext]: Constructor threw exception; nested exception is java.lang.NullPointerException
->> 262 | run in java.util.concurrent.FutureTask
---
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanInstantiationException: Failed to instantiate [org.codehaus.groovy.grails.domain.GrailsDomainClassMappingContext]: Constructor threw exception; nested exception is java.lang.NullPointerException
->> 262 | run in java.util.concurrent.FutureTask
---
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by NullPointerException: null
->> 333 | hash in java.util.concurrent.ConcurrentHashMap
---
| 988 | get in ''
| 280 | initializePersistentEntity in org.grails.datastore.mapping.model.AbstractMappingContext
| 232 | addPersistentEntityInternal in ''
| 216 | addPersistentEntity in ''
| 262 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . in java.lang.Thread
Error |
Forked Grails VM exited with error
`
Contributor guide
Research direction
The report uses an abstract BaseDomain in src/groovy with static mapWith = "mongo" and fails while constructing grailsDomainClassMappingContext. Start by reproducing the inheritance case with MongoDB, then trace the null during mapping-context initialization; done when the application starts with the abstract base class and the Hibernate behavior remains unaffected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, mongodb
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100