Deploying Grails application on Glassfish 4 error - grails

i'm trying to deploy Grails application on Glassfish 4 but it was failed and got the below error :
Exception Occurred :Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: 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.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.. Please see server.log for more details.]]
I can't figure out what is causing this error , i tried on google but nothing useful

in the DataSource.groovy commented driverClassName and dialect in the whole file , in the production section i commented URL and used instead the URL the jndiName and was deployed on GlassFish successfully without the previous error . Hope this workaround helps others

The root cause of error is related to hibernate cache configuration:
Invocation of init method failed; nested exception is org.hibernate.cache.NoCacheRegionFactoryAvailableException:
Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given;
please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath..
I would suggest to review/compare cache setting and check cache provider.

Related

"GrailsDomainException: Identity property not found, but required in domain class" only on WebSphere 7

When starting my grails 2.5.3 app with the command "grails run-app" it starts with no issues. But when starting it on WebSphere 7 I am getting the following error:
context.GrailsContextLoaderListener - Error initializing the application: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsDomainException: Identity property not found, but required in domain class [org.codehaus.groovy.grails.plugins.codecs.SHA1BytesCodec]
The mentioned class obviously isn't a domain class but for some reason grails thinks it is.
Usually restarting the app would work but not anymore. All I got this time was making it complain about a different class (also not a domain one, but a service one).
Fixed at Grails 3.1.x and Grails 2.5.x.

grails run-app throws NoClassDefFoundError for domain class

I'm trying to run a Grails app inherited from another developer. It has just one domain class, which we'll call foopackage.DomainObject. When I compile it, a .class file turns up in target/classes just as I'd expect. However, when I try grails run-app, I get
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'pluginManager' defined in ServletContext
resource [/WEB-INF/applicationContext.xml]: Invocation of init method
failed; nested exception is java.lang.NoClassDefFoundError: Could not
initialize class foopackage.DomainObject
At first I thought this might be because DomainObject was trying to talk to a nonexistent database in a broken static initializer, so I reduced it down to just
package foopackage
class DomainObject {}
And I still get the same error. Maybe there's some underlying configuration/GORM problem, but it's not showing up with --stacktrace. Any hints?
All right, it turns out it was the static initializer after all, and when I thought I'd ruled that out I was editing the wrong file.

Using #TestFor in unit test for bean that uses constructor arguments throws an error (Grails 2.0.0RC1)

I'm trying to create a unit test for a service class that uses a constructor argument. I have already configured an entry in the grails-app/conf/spring/resources.groovy to allow Spring to create the bean using the constructor argument.
Running an integration test for the service class works without problem, however, running a unit test that uses #TestFor, the following exception shows up:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sampleService': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [ph.jojopad.SampleService]: No default constructor found; nested exception is java.lang.NoSuchMethodException: ph.jojopad.SampleService.<init>()
at grails.test.mixin.services.ServiceUnitTestMixin.mockService(ServiceUnitTestMixin.groovy:54)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [ph.jojopad.SampleService]: No default constructor found; nested exception is java.lang.NoSuchMethodException: ph.jojopad.SampleService.<init>()
Caused by: java.lang.NoSuchMethodException: ph.jojopad.SampleService.<init>()
It seems that #TestFor only expects a bean that uses the default constructor. Looking at the documentation of Grails I can't find any references on how to use #TestFor for beans with constructor arguments. I was expecting that with the correct bean configuration at grails-app/conf/spring/resources.groovy would do the trick.

grails - error executing bootstrap (Error creating bean with name 'messageSource')

I made some seemingly harmless changes (added a few domain classes, added the plugin shopping-cart), and now apparently the BootStrap.groovy class doesn't execute at all.
While I made a few changes to BootStrap.groovy, I restored a previously good file that works fine, dumbfounded by the error. Also, in the good (old) BootStrap.groovy, I put some println statements at the top of the init action, but those aren't printing out and don't seem to even be reached. Finally, I did an uninstall of the plugin, and after that, deleted the shopping-cart plugin folder manually.
Do you know what this error is, or have any debug guidance? (am running Grails 1.3.7)
Running Grails application..
Configuring Spring Security ...
Configuring Spring Security UI ...
2011-12-09 13:51:33,036 [main] ERROR context.GrailsContextLoader -
Error executing bootstraps: Error creating bean with name
'messageSource': 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.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'sessionFactory': Invocation of init method
failed; nested exception is org.hibernate.MappingException: Type
[null] is not a basic type or a domain class and cannot be mapped.
Either specify a type within the [mapping] block or use a basic type
(String, Integer etc.)
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'messageSource': 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.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'sessionFactory': Invocation of init method
failed; nested exception is org.hibernate.MappingException: Type
[null] is not a basic type or a domain class and cannot be mapped.
Either specify a type within the [mapping] block or use a basic type
(String, Integer etc.) at
org.grails.tomcat.TomcatServer.startSecure(TomcatServer.groovy:289)
at grails.web.container.EmbeddableServer$startSecure.call(Unknown
Source) at
_GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:152)
at
_GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy) at
_GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280)
at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149) at
_GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy) at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116) at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy) at _GrailsRun_groovy$_run_closure2.doCall(_GrailsRun_groovy:66) at RunApp$_run_closure1.doCall(RunApp.groovy:30) at
gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381) at
gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415) at
gant.Gant$_dispatch_closure7.doCall(Gant.groovy) at
gant.Gant.withBuildListeners(Gant.groovy:427) at
gant.Gant.this$2$withBuildListeners(Gant.groovy) at
gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source) at
gant.Gant.dispatch(Gant.groovy:415) at
gant.Gant.this$2$dispatch(Gant.groovy) at
gant.Gant.invokeMethod(Gant.groovy) at
gant.Gant.executeTargets(Gant.groovy:590) at
gant.Gant.executeTargets(Gant.groovy:589) at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: 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.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'sessionFactory': Invocation of init method
failed; nested exception is org.hibernate.MappingException: Type
[null] is not a basic type or a domain class and cannot be mapped.
Either specify a type within the [mapping] block or use a basic type
(String, Integer etc.) ... 24 more Caused by:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'sessionFactory': Invocation of init method
failed; nested exception is org.hibernate.MappingException: Type
[null] is not a basic type or a domain class and cannot be mapped.
Either specify a type within the [mapping] block or use a basic type
(String, Integer etc.) ... 24 more Caused by:
org.hibernate.MappingException: Type [null] is not a basic type or a
domain class and cannot be mapped. Either specify a type within the
[mapping] block or use a basic type (String, Integer etc.) ... 24
more
Process finished with exit code 1
I removed all the new domain classes and references to them, and the error went away. I'll update this as soon as I figure out what the problem is, hopefully not related to a domain change to one of the Spring Security classes (User).
Ok, the problem is/was, I had an enum declaration at the top of one of the domain classes I added. If I move the enum declaration below the class declaration, then all is good. I imagine this is a hibernate error / problem?
I would guess that you have a problem in one of your domain classes where you use a "def" or some other invalid type in the domain class for one of the fields.

Possible to create a domain class that is NOT mapped to a database table?

I'm using Grails 1.2.1. I'm converting a Java app to a Grails app and I had a Java object that I thought I'd create a grails domain for. However, the object does not rely on an underlying database table. When I startup my app, I'm getting the error,
ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'messageSource': 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.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'sessionFactory': Invocation of init method
failed; nested exception is org.hibernate.MappingException: Could not
determine type for: java.io.InputStream, at table:
http_cache_response, for columns: [org.hibernate.mapping.Column(body)]
Am I misusing the domain? Should this object just be a regular class in src/groovy? Thanks, - Dave
Yes, domain objects are specifically database-mapped objects. Not domain in the DDD sense.
Depending on if the class is a singleton or not it should either be a service or a class in src/groovy.
It's possible to create a class that does not have an underlying domain object. There are 2 cases:
You want an object to use in Controller, you may create a Command Object.
If you want to create a pure java or groovy class, you can create it in src/java or src/groovy.
You might want to check out mapWith property of domain classes:
static mapWith = "none" should do the trick
I would say if your not going to use the class as a grails style domain object, it's better to put it in src/java and use them like any other class.

Resources