GORM inheritance issue - orm

I'm blocked on this GORM inheritance problem I have and id appreciate some fresh eyes to have a look over this problem. (Im using Grails 1.3.2)
I have a base abstract class...
abstract class MaintenanceSchedule {
static belongsTo = [ maintenanceTask:MaintenanceTask ]
}
and I want to extend it like so...
class OneOffSchedule extends MaintenanceSchedule {
Date scheduleDate
static constraints = {
scheduleDate(nullable:false)
}
private static OneOffSchedule getReferenceOneOffSchedule() {
return new OneOffSchedule(scheduleDate:new Date())
}
}
when I try and run my application I get the following stack trace.
2010-06-26 12:01:43,090 [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: An association from the table maintenance_task refers to an unmapped class: preventIT.maintenance.MaintenanceSchedule
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: An association from the table maintenance_task refers to an unmapped class: preventIT.maintenance.MaintenanceSchedule
at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:164)
at grails.web.container.EmbeddableServer$start.call(Unknown Source)
at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:159)
at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:282)
at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:150)
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_closure1.doCall(_GrailsRun_groovy:59)
at RunApp$_run_closure1.doCall(RunApp.groovy:33)
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)
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: An association from the table maintenance_task refers to an unmapped class: preventIT.maintenance.MaintenanceSchedule
... 23 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: An association from the table maintenance_task refers to an unmapped class: preventIT.maintenance.MaintenanceSchedule
... 23 more
Caused by: org.hibernate.MappingException: An association from the table maintenance_task refers to an unmapped class: preventIT.maintenance.MaintenanceSchedule
... 23 more

The problem is arguably a bug in gorm (maybe hibernate, not sure where the root of the bug lies) in that it does not persist abstract classes and breaks polymorphic relationships . Presumably you've got a
static hasMany = [schedules:MaintenanceSchedule]
in your MaintenanceTask class. If your MaintenanceSchedule class is really just like it appears in your post, you can work around the problem by removing the abstract descriptor on the class. If you want to prevent someone from creating a MaintenanceSchedule you can explicitly add a protected no argument constructor.
If you want to have abstract methods in the MaintenanceSchedule then the approach doesn't work so well. But, if you either remove the abstract keyword or the relationship on MaintenanceTask your compiler error should go away.

In Grails version 1.4 this is going to be solved. It's actually solved... but we have to wait to the 1.4 stable version be released.
See http://jira.grails.org/browse/GRAILS-2583

Related

How to solve it

Description: Parameter 0 of constructor in com.example.mandateregistration.service.MandateRegistrationService required a bean of type 'com.example.mandateregistration.dao.RegistrationDao' that could not be found. Action: Consider defining a bean of type 'com.example.mandateregistration.dao.Regis

Munit issue Error creating bean with name muleNotificationManager

java.lang.RuntimeException: org.mule.api.config.ConfigurationException:
Error creating bean with name '_muleNotificationManager': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name '_muleTransactionManager': Unsatisfied dependency expressed through field 'customTxManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_muleTransactionManager': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException (org.mule.api.lifecycle.InitialisationException
Few things to evaluate here.
1. Make sure you installed the Munit plugin in anypoint studio.
2. Make sure you added property files to context spring:beans>
context:property-placeholder location="UAT.properties" />
spring:import resource="classpath:Implementation.xml"/> --Probably you only had this one./spring:beans>

org.springframework.data.mapping.PropertyReferenceException: No property greaterThan found for type

Does MongoRepository has $and operator? I was getting error when i try with and operator like below. I have checked the document and haven't noticed "and" keyword.
public interface AssetRepository extends MongoRepository<Asset, String>{
#Query("select a from Asset a where ownerId = ? and timeUpdated > ?")
public List<Asset> findByOwnerIdAndGreaterThan(final String ownerId, Date timeUpdated);
}
Error
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'assetRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property greaterThan found for type Asset!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
... 29 more
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property greaterThan found for type Asset!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241)
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76)
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:235)
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:373)
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:353)
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:87)
at org.springframework.data.mongodb.repository.query.PartTreeMongoQuery.<init>(PartTreeMongoQuery.java:53)
at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory$MongoQueryLookupStrategy.resolveQuery(MongoRepositoryFactory.java:128)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:369)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:192)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:239)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:225)
at org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean.afterPropertiesSet(MongoRepositoryFactoryBean.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
Judging from your exception your query lookup strategy is CREATE, or you don't import #Query from the correct namespace (package).
You should change the method name to findByOwnerIdAndTimeUpdatedGreaterThan, assuming the Asset class has a timeUpdated property.
Or, resolving back to default lookup strategy, the following should work (I think):
#Query("{ 'ownerId' : ?0 , 'timeUpdated' : {$gt : ?1}}")
Notice that you currently use a JPA syntax in #Query, and not MongoDB.
The code doesn't work for two reasons:
You're using JPQL with MongoDB which is not supported. If you want to manually define the query, use a MongoDB query (i.e. JSON).
The exception indicates the query is derived from the method name. findByOwnerIdAndGreaterThan doesn't make too much sense, as you need to define a property you want to apply GreaterThan to. So it probably needs to be something along the lines of findByOwnerIdAndTimeUpdatedGreaterThan judging from what you have listed as JPQL document.

jhipster run embedded jar with prod profile - issue with liquibase

I have packaged my app with :
mvn -Pprod package
Then I ran
java -jar myapp-0.0.1-SNAPSHOT.war
it works fine.
But if I run :
java -jar myapp-0.0.1-SNAPSHOT.war --spring.profiles.active=prod
I am getting this error:
[ERROR] org.springframework.boot.context.embedded.tomcat.ServletContextInitializerLifecycleListener - Error starting Tomcat context: org.springframework.beans.factory.BeanCreationException
[WARN] org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:124) [spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474) ~[spring-context-4.1.3.RELEASE.jar!/:4.1.3.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109) [spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691) [spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321) [spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at com.myapp.Application.main(Application.java:57) [classes!/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_25]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_25]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53) [bioandbio-0.0.1-SNAPSHOT.war:na]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_25]
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:97) ~[spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:74) ~[spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:374) ~[spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:150) ~[spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:148) [spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:121) [spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
... 11 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService com.myapp.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDetailsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.myapp.repository.UserRepository com.myapp.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#1f1288f5' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1f1288f5': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [com/myapp/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.ValidationFailedException: Validation Failed:
1 change sets check sum
classpath:config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster is now: 7:788e6cd59e4764c45e1b83437356e748
I don't understand why prod profile causes this issue.
If someone knows what's wrong here
Thank you.
Reading all the way to the bottom of the stack trace, I see that the root cause is a liquibase checksum validation failure. I'm not sure how familiar you are with liquibase, but it is a tool that is embedded inside jhipster that is used to manage database schema changes as your objects change. What liquibase does is use an XML format to describe the database schema as a series of 'changesets'. When liquibase deploys a changeset (i.e. a changeset that says 'changeset with id "CreateTableFoo" is "create table foo with columns bar baz etc") is that it actually creates the table, and then it also adds a row to a table called 'databasechangelog' that records that the changeset "CreateTableFoo" was successfully applied at such and such a time, and the checksum of that changeset was some value. Now, if you come along and change the changeset xml file so that the changeset "CreateTableFoo" instead creates a table with a different name or different columns, then the checksum calculated for that changeset also changes, so when you try to update the schema liquibase says "Wait! Something wrong!"
So that is what is happening here.
Error creating bean with name 'liquibase' defined in class path resource [com/myapp/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.ValidationFailedException: Validation Failed:
1 change sets check sum
classpath:config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster is now: 7:788e6cd59e4764c45e1b83437356e748
What this indicates is that the prod database already has had a liquibase update run on it to populate the schema, but that the changeset has changed since that initial deploy. I am not familiar with how jhipster uses liquibase, so you would need to look at the file classpath:config/liquibase/changelog/00000000000000_initial_schema.xml to see what database schema it is trying to set up, and compare that to the schema that is actually in place in production.
Now that things are out of sync, you'll have to figure out a way to get them back in sync, which is more complicated than can be answered here and depends greatly on what the differences between the changelog and the production schema are.

Weblogic + Stateless Local Bean + DataSource Injection mistake

I Have a Stateless Local Bean like that:
#Stateless(name="GerencialFacadeBean", mappedName="GerencialFacade")
public class GerencialFacadeBean implements GerencialFacadeBeanLocal {
#Resource(name="jdbc/adq_sistint", mappedName = "jdbc/adq_sistint")
private DataSource dataSource;
.. }
So, when I take use of this bean I got the follow exception:
Caused by: com.bea.core.repackaged.springframework.beans.factory.BeanCreationException: Dependency injection failure: can't find the bean definition about class interface javax.sql.DataSource; nested exception is com.bea.core.repackaged.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.sql.DataSource] is defined: No beans of type javax.sql.DataSource; owner=com.bea.core.repackaged.springframework.context.support.GenericApplicationContext#5d225fc1: display name [com.bea.core.repackaged.springframework.context.support.GenericApplicationContext#5d225fc1]; startup date [Mon Oct 15 16:30:12 BRT 2012]; parent: com.bea.core.repackaged.springframework.context.support.GenericApplicationContext#885e019
at com.oracle.pitchfork.inject.Jsr250Metadata.applyInjections(Jsr250Metadata.java:241)
at com.oracle.pitchfork.inject.Jsr250Metadata.inject(Jsr250Metadata.java:223)
at com.oracle.pitchfork.inject.Jsr250Metadata.injectAndPostConstruct(Jsr250Metadata.java:253)
at com.oracle.pitchfork.inject.Jsr250MetadataBeanPostProcessor.postProcessAfterInstantiation(Jsr250MetadataBeanPostProcessor.java:40)
at com.bea.core.repackaged.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:957)
at com.bea.core.repackaged.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)
... 66 more
Caused by: com.bea.core.repackaged.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.sql.DataSource] is defined: No beans of type javax.sql.DataSource; owner=com.bea.core.repackaged.springframework.context.support.GenericApplicationContext#5d225fc1: display name [com.bea.core.repackaged.springframework.context.support.GenericApplicationContext#5d225fc1]; startup date [Mon Oct 15 16:30:12 BRT 2012]; parent: com.bea.core.repackaged.springframework.context.support.GenericApplicationContext#885e019
at com.oracle.pitchfork.inject.Jsr250Metadata.getUniqueInstanceOfType(Jsr250Metadata.java:304)
at com.oracle.pitchfork.inject.Jsr250Metadata.resolveByType(Jsr250Metadata.java:298)
at com.oracle.pitchfork.inject.Jsr250Metadata.resolve(Jsr250Metadata.java:285)
at com.oracle.pitchfork.inject.Jsr250Metadata.applyInjections(Jsr250Metadata.java:235)
Important:
I use this EJB from a Webservice (in the same EAR), like:
.. class MyWebService.. {
#EJB(name="GerencialFacadeBean", mappedName="GerencialFacade")
private GerencialFacadeBeanLocal gerencialBean;
}
and, if I try got the datasource on the Webservice´s class it work sucessfully.
EDIT:
Another consideration: using REMOTE interface it works. But I want to use it with Local interface.
I'm using Weblogic 10.3.5. My Datasource is created and works fine in other applications (that get it directly by JNDI), So, what I´m getting this error?