gorm Inheritance causes DuplicateMappingException - grails

My webapp behaves strangely when a child class is reloaded
package test
class Test {
Integer amount
//static mapping = {
// tablePerHierarchy true
// autoImport false
//}
}
and the child class
package test
class Test1 extends Test{
String cardNumber
}
new table is created after the parent class is reloaded
but grails console throws error if I reload child class
ERROR org.grails.plugins.AbstractGrailsPluginManager - Plugin [domainClass:3.0.9] could not reload changes to file [/home/gkiko/workspace/test/grails-app/domain/test/Test1.groovy]: Error creating bean with name 'org.grails.internal.SESSION_FACTORY_HOLDER-reloaded': Cannot create inner bean '(inner bean)#d22a35c' of type [org.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean] while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#d22a35c': Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate class/entity mapping test.Test1
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.grails.internal.SESSION_FACTORY_HOLDER-reloaded': Cannot create inner bean '(inner bean)#d22a35c' of type [org.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean] while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#d22a35c': Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate class/entity mapping test.Test1
.... some more stacktrace
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#d22a35c': Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate class/entity mapping test.Test1
How can I fix the problem?
Grails Version: 3.0.11
Groovy Version: 2.4.5
JVM Version: 1.7.0_91

You should restart your application if you are making any changes to your domain class. Although it is working fine in case you are modifying the parent class, but still the dynamic domain entities creation feature doesn't work perfectly.

Related

EnableWebFluxSecurity contadiction with web dependency

I am trying to annotate SecurityWebFilterChain class with #EnableWebFluxSecurity :
#EnableWebFluxSecurity
public class AccessIqWebSecurityConfigurerAdapter {
I am getting the following error while boot the app:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name
'org.springframework.security.config.annotation.web.reactive.WebFluxSecurityConfiguration':
Unsatisfied dependency expressed through field
'securityWebFilterChains'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'springSecurityFilterChain' defined in class
path resource
[com/config/AccessIqWebSecurityConfigurerAdapter.class]:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate
[org.springframework.security.web.server.SecurityWebFilterChain]:
Factory method 'springSecurityFilterChain' threw exception; nested
exception is java.lang.IllegalArgumentException:
clientRegistrationRepository cannot be null
When I remove compile("org.springframework.boot:spring-boot-starter-web"). It works. but I need compile("org.springframework.boot:spring-boot-starter-web") for swagger, Mockmvc etc. any idea?
As stated in the reference documentation, adding the spring-boot-starter-web dependency to your application will tell Spring Boot to configure it as a Spring MVC application.
You could give another hint to Spring Boot to make it still a Spring WebFlux application (through SpringApplication.setWebApplicationType(WebApplicationType.REACTIVE)), but it wouldn't help in your case:
You have to use a swagger integration that's compatible with WebFlux (I don't know if that exists)
You should consider WebTestClient instead of MockMvc

ClassCastException for MappingFactory to ToMany while porting to grails 3

When trying to run command grails run-app --stacktrace, grails is throwing this error :
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 java.lang.ClassCastException: org.grails.datastore.mapping.model.MappingFactory$10 cannot be cast to org.grails.datastore.mapping.model.types.ToMany
I commented static hasMany from all the domain classes but error still persisted, until I replaced it with hibernate3 in my build.gradle
How can I solve this using hibernate4?
I found the solution, actually it had to do with embedded grails domain property.
As #deepen mention, this error is related with the mapping setup of the embedded domain classes. In my case, I was using multiples databases (mongodb gorm 6.0.12 + jtds (sql server)), and some of the documents had embedded properties (defined in the same class).
DomainA.groovy
class DomainA
static hasMany = [domainBs: DomainB]
static embedded = ['domainBs']
static mapWith = "mongo"
class DomainB
// if embedded: what's the point of this?
static belongsTo = [domainB: DomainA]
// if i'll use it as embedded, doesn't add nothing
static mapWith = "mongo"
In short, if I comment belongsTo and mapWith in the definition of the embedded class, the issue was solved. If not, must remember to mapWith embedded class with same datasource as container class.

Grails upgrade from 2.5.1 to 3.1.4

While migrating my grails 2 application to grails 3 I am facing some weird situation as:
I have two domain named Service.groovy and Test.groovy. Test domain has hasMany relation with Service e.g static hasMany = [services: Service].
Now while running the application it throws exception as
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'grailsApplicationPostProcessor' defined in
testproject.Application: Bean instantiation via factory method failed;
nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [grails.boot.config.GrailsApplicationPostProcessor]:
Factory method 'grailsApplicationPostProcessor' threw exception;
nested exception is java.lang.ClassCastException: com.test.Service
cannot be cast to java.lang.Class
I have created test project in grails 3 and it seems like new grails is not excepting Service.groovy as domain.
Please Kindly suggest.

Spring security acl and Postgres

Using "spring-security-acl:2.0-RC1" as a Grails plugin with an application linked to a Postgres 9.3 data source, the following bug happens at startup:
.. finished configuring Spring Security ACL
2013-12-19 13:20:19,588 ERROR [GrailsContextLoader] - Error initializing the application: Error creating bean with name 'webExpressionVoter': Cannot resolve reference to bean 'webExpressionHandler' while setting bean property 'expressionHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webExpressionHandler': Cannot resolve reference to bean 'permissionEvaluator' while setting bean property 'permissionEvaluator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'permissionEvaluator': Cannot resolve reference to bean 'aclService' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityAclAclService': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCache': Cannot resolve reference to bean 'ehcacheAclCache' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: aclCache Cache: Could not create disk store. This CacheManager configuration does not allow creation of DiskStores. If you wish to create DiskStores, please configure a diskStore path.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webExpressionVoter': Cannot resolve reference to bean 'webExpressionHandler' while setting bean property 'expressionHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webExpressionHandler': Cannot resolve reference to bean 'permissionEvaluator' while setting bean property 'permissionEvaluator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'permissionEvaluator': Cannot resolve reference to bean 'aclService' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityAclAclService': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCache': Cannot resolve reference to bean 'ehcacheAclCache' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: aclCache Cache: Could not create disk store. This CacheManager configuration does not allow creation of DiskStores. If you wish to create DiskStores, please configure a diskStore path.
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webExpressionHandler': Cannot resolve reference to bean 'permissionEvaluator' while setting bean property 'permissionEvaluator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'permissionEvaluator': Cannot resolve reference to bean 'aclService' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityAclAclService': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCache': Cannot resolve reference to bean 'ehcacheAclCache' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: aclCache Cache: Could not create disk store. This CacheManager configuration does not allow creation of DiskStores. If you wish to create DiskStores, please configure a diskStore path.
... 4 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'permissionEvaluator': Cannot resolve reference to bean 'aclService' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityAclAclService': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCache': Cannot resolve reference to bean 'ehcacheAclCache' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: aclCache Cache: Could not create disk store. This CacheManager configuration does not allow creation of DiskStores. If you wish to create DiskStores, please configure a diskStore path.
... 4 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityAclAclService': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCache': Cannot resolve reference to bean 'ehcacheAclCache' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: aclCache Cache: Could not create disk store. This CacheManager configuration does not allow creation of DiskStores. If you wish to create DiskStores, please configure a diskStore path.
... 4 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCache': Cannot resolve reference to bean 'ehcacheAclCache' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: aclCache Cache: Could not create disk store. This CacheManager configuration does not allow creation of DiskStores. If you wish to create DiskStores, please configure a diskStore path.
... 4 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: aclCache Cache: Could not create disk store. This CacheManager configuration does not allow creation of DiskStores. If you wish to create DiskStores, please configure a diskStore path.
... 4 more
Caused by: net.sf.ehcache.CacheException: aclCache Cache: Could not create disk store. This CacheManager configuration does not allow creation of DiskStores. If you wish to create DiskStores, please configure a diskStore path.
at net.sf.ehcache.store.compound.factories.DiskOverflowStorageFactory.getDataFile(DiskOverflowStorageFactory.java:81)
at net.sf.ehcache.store.compound.factories.DiskOverflowStorageFactory.<init>(DiskOverflowStorageFactory.java:73)
at net.sf.ehcache.store.compound.impl.OverflowToDiskStore.create(OverflowToDiskStore.java:63)
at net.sf.ehcache.Cache.initialise(Cache.java:1113)
at net.sf.ehcache.CacheManager.addCacheNoCheck(CacheManager.java:1100)
at net.sf.ehcache.CacheManager.addCache(CacheManager.java:1006)
... 4 more
Tested with or without "cache 1.1.1" activated, same result
No issue with mysql
Env: grails 2.3.4
A JIRA ticket will be open in the coming days if no workaround found by myself or any contributor. Thanks.
You can reconfigure the bean in grails-app/conf/spring/resources.groovy to not overflow to disk:
beans = {
ehcacheAclCache(EhCacheFactoryBean) {
cacheManager = ref('aclCacheManager')
cacheName = 'aclCache'
overflowToDisk = false
}
}

Connecting a groovy application to SQL server Express

I was following the tutorial below but there must be some significant steps where knowledge, that I don't have, is being assumed.
http://padcom13.blogspot.co.uk/2011/01/setting-up-sql-server-2008-express-to.html
below is the setup in my datasource.groovy
username = "sa"
password = ""
url = "jdbc:sqlserver://localhost:1433;databaseName=Sandpit"
driverClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
dialect = "org.hibernate.dialect.SQLServerDialect"
and below is the error popping up on run app command
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.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory':
Cannot resolve reference to bean 'lobHandlerDetector' while setting bean property 'lobHandler';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'lobHandlerDetector': Invocation of init method failed;
nested exception is org.springframework.jdbc.support.MetaDataAccessException:
Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException:
Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
Message: 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':
Cannot resolve reference to bean 'lobHandlerDetector' while setting bean property 'lobHandler';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'lobHandlerDetector':
Invocation of init method failed; nested exception is
org.springframework.jdbc.support.MetaDataAccessException:
Error while extracting DatabaseMetaData; nested exception is
org.apache.commons.dbcp.SQLNestedException:
Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
Been working on this a couple of days without seeing my app run..... any advice?
The root cause is Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
That's because your driver is missing in the classpath. In the case of SQL Server you need to copy the jar to the lib folder.
In other cases like MySQL you can declare as a maven dependency.
We are doing the same thing like you.
Therefor, we have the sqljdbc.jar in our /lib -directory.
In our DataSource.groovy we have then:
dbCreate = "update" // one of 'create', 'create-drop','update'
username = "dbo"
driverClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
url = "jdbc:sqlserver://devdb02:1433;databaseName=my_database;"
I remember that just the .jar is not enough, I think you need to install a small part into your windows/unix-directory e.g. from here:
http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774
(that's also needed if you maybe use PHP with MSSQL)

Resources