Spring 4 - Config XML jpa:repositories throwing NoSuchMethodError BeanDefinitionParserDelegate.getEnvironment() - spring

I am attempting to integrate the Gradle project here into a Maven project of mine. The file data-context.xml is used to configure Hibernate with Spring to generate the repositories used for authenticating User requests to the RESTful interface.
Everything is working, but when I attempt to deploy onto a tomcat server I see the following issue:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityContextFilter' defined in file [/var/lib/tomcat6/webapps/services/WEB-INF/classes/com/services/filter/SecurityContextFilter.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.services.user.UserRepository]: : Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract com.services.user.domain.User com.services.user.UserRepository.findBySession(java.lang.String)!; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract com.services.user.domain.User com.services.user.UserRepository.findBySession(java.lang.String)!
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:185) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1139) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1042) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) ~[spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) ~[spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4210) [catalina-6.0.24.jar:na]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4709) [catalina-6.0.24.jar:na]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791) [catalina-6.0.24.jar:na]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771) [catalina-6.0.24.jar:na]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526) [catalina-6.0.24.jar:na]
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:905) [catalina-6.0.24.jar:na]
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:740) [catalina-6.0.24.jar:na]
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:500) [catalina-6.0.24.jar:na]
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277) [catalina-6.0.24.jar:na]
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321) [catalina-6.0.24.jar:na]
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142) [catalina-6.0.24.jar:na]
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) [catalina-6.0.24.jar:na]
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722) [catalina-6.0.24.jar:na]
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) [catalina-6.0.24.jar:na]
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) [catalina-6.0.24.jar:na]
at org.apache.catalina.core.StandardService.start(StandardService.java:516) [catalina-6.0.24.jar:na]
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710) [catalina-6.0.24.jar:na]
at org.apache.catalina.startup.Catalina.start(Catalina.java:593) [catalina-6.0.24.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_79]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_79]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_79]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_79]
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) [bootstrap-6.0.24.jar:na]
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) [bootstrap-6.0.24.jar:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract com.services.user.domain.User com.services.user.UserRepository.findBySession(java.lang.String)!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
... 39 common frames omitted
Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract com.services.user.domain.User com.services.user.UserRepository.findBySession(java.lang.String)!
at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:92) ~[spring-data-jpa-1.8.0.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.SimpleJpaQuery.<init>(SimpleJpaQuery.java:62) ~[spring-data-jpa-1.8.0.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:72) ~[spring-data-jpa-1.8.0.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromQueryAnnotation(JpaQueryFactory.java:53) ~[spring-data-jpa-1.8.0.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:136) ~[spring-data-jpa-1.8.0.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:204) ~[spring-data-jpa-1.8.0.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:73) ~[spring-data-jpa-1.8.0.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:347) ~[spring-data-commons-1.10.0.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:185) ~[spring-data-commons-1.10.0.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:239) ~[spring-data-commons-1.10.0.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:225) ~[spring-data-commons-1.10.0.RELEASE.jar:na]
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92) ~[spring-data-jpa-1.8.0.RELEASE.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
... 50 common frames omitted
Caused by: java.lang.NullPointerException: null
at org.hibernate.internal.util.StringHelper.root(StringHelper.java:345) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1994) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:61) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1970) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.hql.internal.ast.tree.FromElement.getIdentityColumns(FromElement.java:355) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.hql.internal.ast.tree.IdentNode.resolveAsAlias(IdentNode.java:167) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.hql.internal.ast.tree.IdentNode.resolve(IdentNode.java:104) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:126) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:121) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.hql.internal.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:959) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.propertyRef(HqlSqlBaseWalker.java:1146) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2253) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:2194) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1476) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:573) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:249) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:278) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:206) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:131) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:93) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1836) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:328) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_79]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_79]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_79]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_79]
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:344) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at com.sun.proxy.$Proxy50.createQuery(Unknown Source) ~[na:na]
at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:86) ~[spring-data-jpa-1.8.0.RELEASE.jar:na]
... 63 common frames omitted
I am inclined to think that this is caused by the data-context.xml not initialising properly and therefore making the query validation fail. Below are samples of my code, and the spring dependancies I have included in my pom.
Data-context.xml -
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/integration/jdbc
http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/data/repository
http://www.springframework.org/schema/data/repository/spring-repository.xsd">
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="samplePersistenceUnit"/>
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"/>
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
</bean>
<jpa:repositories base-package="com.services.user" />
<!--
the above shows the following error in Eclipse :
java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.getEnvironment()
-->
<bean class="org.springframework.orm.jpa.JpaTransactionManager"
id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
</property>
</bean>
<tx:annotation-driven/>
...
</beans>
Domain.User class -
#Entity
#Table(name="rest_user")
public class User extends BaseEntity {
#Id #GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private static final int HASH_ITERATIONS = 1000;
private String firstName;
private String lastName;
private String emailAddress;
private String hashedPassword;
private boolean isVerified;
#Enumerated(EnumType.STRING)
private Role role;
#OneToMany(mappedBy="user",
targetEntity=VerificationToken.class,
cascade= CascadeType.ALL)
#LazyCollection(LazyCollectionOption.FALSE)
private List<VerificationToken> verificationTokens = new ArrayList<VerificationToken>();
#OneToOne(fetch = FetchType.LAZY,
mappedBy = "user",
cascade = CascadeType.ALL)
private AuthorizationToken authorizationToken;
Domain.AuthorizationToken class -
#Entity
#Table(name="rest_authorization_token")
public class AuthorizationToken extends AbstractPersistable<Long> {
private final static Integer DEFAULT_TIME_TO_LIVE_IN_SECONDS = (60 * 60 * 24 * 30); //30 Days
#Id #GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
#Column(length=36)
private String token;
private Date timeCreated;
private Date expirationDate;
#OneToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "token")
private User user;
UserRepository class -
public interface UserRepository extends JpaRepository<User, Long> {
User findByEmailAddress(String emailAddress);
#Query("select u from User u where uuid = ?")
User findByUuid(String uuid);
#Query("select u from User u where u in (select user from AuthorizationToken where lastUpdated < ?)")
List<User> findByExpiredSession(Date lastUpdated);
#Query("select u from User u where u = (select user from AuthorizationToken where token = ?)")
User findBySession(String token);
}
VerificationToken class -
#Entity
#Table(name = "rest_verification_token")
public class VerificationToken extends BaseEntity {
private static final int DEFAULT_EXPIRY_TIME_IN_MINS = 60 * 24; //24 hours
#Column(length=36)
private String token;
private Date expiryDate;
#Enumerated(EnumType.STRING)
private VerificationTokenType tokenType;
private boolean verified;
#ManyToOne
User user;
public VerificationToken() {
super();
this.token = UUID.randomUUID().toString();
this.expiryDate = calculateExpiryDate(DEFAULT_EXPIRY_TIME_IN_MINS);
}
public VerificationToken(User user, VerificationTokenType tokenType, int expirationTimeInMinutes) {
this();
this.user = user;
this.tokenType = tokenType;
this.expiryDate = calculateExpiryDate(expirationTimeInMinutes);
}
pom.xml Spring dependancies - (I have made sure there are no conflicts)

For starters I suggest fixing your entities, you have a basic one-to-one mapping but you are making it way to complex, also you don't need a composite primary key. Next your queries are also way to complex you don't need the join you can simply return the user field from the AuthorizationToken.
Entities
All of your entities are extending either directly or indirectly AbstractPersistable that class already has an id field. Adding an additional #Id isn't needed and will only confuse JPA as you now all of a sudden require a composite primary key. The solution is quite easy remove the custom id fields from the entities.
#Entity
#Table(name="rest_authorization_token")
public class AuthorizationToken extends AbstractPersistable<Long> {
#Column(length=36)
private String token;
#OneToOne(fetch = FetchType.LAZY)
#PrimaryKeyJoinColumn
private User user;
}
The AuthorizationToken isn't embeddable so remove the annotation. For the one-to-one mapping add the #PrimaryKeyJoinColumn annotation. The token field doesn't need to be an #Id there is already an primary key field in the AbstractPersistable.
On the User entity remove the #IdClass as that isn't needed for a simple mapping. If you don't want a bi-directional relationship remove the authorizationToken field from the User entity. If you want to use it, just remove the #Id.
#Entity
#Table(name="rest_user")
public class User extends BaseEntity {
#OneToOne(fetch = FetchType.LAZY,
mappedBy = "user",
cascade = CascadeType.ALL)
private AuthorizationToken authorizationToken;
}
Note: I omitted the rest of the entities code as that remained unchanged.
Now that the entities are cleaned up, simplify the queries by just returning the user field from the AuthorizationToken.
public interface UserRepository extends JpaRepository<User, Long> {
User findByEmailAddress(String emailAddress);
User findByUuid(String uuid);
#Query("select user from AuthorizationToken where lastUpdated < ?")
List<User> findByExpiredSession(Date lastUpdated);
#Query("select user from AuthorizationToken where token = ?")
User findBySession(String token);
}
I also noticed that you had a #Query for the findByUuid that shouldn't be needed as Spring Data JPA can generate that query for you.

Related

Spring table relationship problems

I have two entities Product and Image, the image has a Product foreign key.
When i try to run the code i get the following error
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'mainController': Unsatisfied dependency
expressed through field 'imageRepository'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'imageRepository': Invocation of init method
failed; nested exception is
org.springframework.data.mapping.PropertyReferenceException: No
property product found for type Image! at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
~[spring-context-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
~[spring-context-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
~[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
model.Application.main(Application.java:10) [classes/:na] Caused by:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'imageRepository': Invocation of init method
failed; nested exception is
org.springframework.data.mapping.PropertyReferenceException: No
property product found for type Image! at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] ... 19 common
frames omitted Caused by:
org.springframework.data.mapping.PropertyReferenceException: No
property product found for type Image! at
org.springframework.data.mapping.PropertyPath.(PropertyPath.java:77)
~[spring-data-commons-1.13.7.RELEASE.jar:na] at
org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329)
~[spring-data-commons-1.13.7.RELEASE.jar:na] at
org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309)
~[spring-data-commons-1.13.7.RELEASE.jar:na] at
org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272)
~[spring-data-commons-1.13.7.RELEASE.jar:na] at
org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243)
~[spring-data-commons-1.13.7.RELEASE.jar:na] at
org.springframework.data.repository.query.parser.Part.(Part.java:76)
~[spring-data-commons-1.13.7.RELEASE.jar:na] at
org.springframework.data.repository.query.parser.PartTree$OrPart.(PartTree.java:247)
~[spring-data-commons-1.13.7.RELEASE.jar:na] at
org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:398)
~[spring-data-commons-1.13.7.RELEASE.jar:na] at
org.springframework.data.repository.query.parser.PartTree$Predicate.(PartTree.java:378)
~[spring-data-commons-1.13.7.RELEASE.jar:na] at
org.springframework.data.repository.query.parser.PartTree.(PartTree.java:89)
~[spring-data-commons-1.13.7.RELEASE.jar:na] at
org.springframework.data.jpa.repository.query.PartTreeJpaQuery.(PartTreeJpaQuery.java:64)
~[spring-data-jpa-1.11.7.RELEASE.jar:na] at
org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:103)
~[spring-data-jpa-1.11.7.RELEASE.jar:na] at
org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:214)
~[spring-data-jpa-1.11.7.RELEASE.jar:na] at
org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:77)
~[spring-data-jpa-1.11.7.RELEASE.jar:na] at
org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.(RepositoryFactorySupport.java:436)
~[spring-data-commons-1.13.7.RELEASE.jar:na] at
org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:221)
~[spring-data-commons-1.13.7.RELEASE.jar:na] at
org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277)
~[spring-data-commons-1.13.7.RELEASE.jar:na] at
org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263)
~[spring-data-commons-1.13.7.RELEASE.jar:na] at
org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:101)
~[spring-data-jpa-1.11.7.RELEASE.jar:na] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] ... 29 common
frames omitted
Product entity
#Entity
#Table(name = "product")
public class Product {
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private String name;
private String description;
private Integer parent_product_id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getParent_product_id() {
return parent_product_id;
}
#OneToMany
#JoinColumn(name = "product_id")
public void setParent_product_id(Integer parent_product_id) {
this.parent_product_id = parent_product_id;
}
}
Image Entity
#Entity
public class Image {
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private String type;
#ManyToOne
private Product product_id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Product getParent_product_id() {
return product_id;
}
public void setProduct_id(Product product_id) {
this.product_id = product_id;
}
}
My ImageRepository
package model;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
// This will be AUTO IMPLEMENTED by Spring into a Bean called userRepository
// CRUD refers Create, Read, Update, Delete
public interface ImageRepository extends CrudRepository<Image, Long> {
List<Image> findByProduct_id(String id);
}
Thanks for the help guys!
Your repository should be:
public interface ImageRepository extends CrudRepository<Image, Long> {
List<Image> findByProductId(Integer id);
}
Your Product Entity should be:
#Entity
#Table(name = "product")
public class Product {
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private String name;
private String description;
#Transient
private Integer parentId;
#ManyToOne
#JoinColumn(name="parent_id")
private Product parentProduct;
//getters/setters
}
And your Image Entity should be:
#Entity
#Table(name = "image")
public class Image {
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private String type;
#ManyToOne
#JoinColumn(name = "product_id")
private Product product;
//getters/setters
}
Please change the name of the product_id to product and change the String type from the repository to Product !
Also try this query :
#Query("select * from Image image where image.product=:product")
List<Image> findByProduct(#Param("product") Product product);

How to inject controller JSF scope view in testNG

Try to inject one controler in my test, call user
#Component("user")
#Scope("view")
public class UserController
Project use:
Spring 4.2.4
JSF 2.2
Hibernate 5
Primefaces 5.3
JUnit
testNG
When ready method getViewMap() my class SysViewScope
When inject controller in test, receive a exception null point, but when deploy system in tomcat, not happened this wrong.
public class SysViewScope implements Scope{
public static final String VIEW_SCOPE_CALLBACKS = "viewScope.callbacks";
public synchronized Object get(String name, ObjectFactory<?> objectFactory){
Object instance = this.getViewMap().get(name);
if (instance == null){
instance = objectFactory.getObject();
this.getViewMap().put(name, instance);
}
return instance;
}
public Object remove(String name){
Object instance = getViewMap().remove(name);
if (instance != null){
Map<String, Runnable> callbacks = (Map<String, Runnable>) getViewMap().
get(VIEW_SCOPE_CALLBACKS);
if (callbacks != null){
callbacks.remove(name);
}
}
return instance;
}
public void registerDestructionCallback(String name, Runnable runnable)
{
Map<String, Runnable> callbacks = (Map<String, Runnable>) getViewMap().
get(VIEW_SCOPE_CALLBACKS);
if (callbacks != null){
callbacks.put(name, runnable);
}
}
public Object resolveContextualObject(String name){
FacesContext facesContext = FacesContext.getCurrentInstance();
FacesRequestAttributes facesRequestAttributes = new FacesRequestAttributes(facesContext);
return facesRequestAttributes.resolveReference(name);
}
public String getConversationId(){
FacesContext facesContext = FacesContext.getCurrentInstance();
FacesRequestAttributes facesRequestAttributes = new FacesRequestAttributes(facesContext);
return facesRequestAttributes.getSessionId() + "-" + facesContext.getViewRoot().getViewId();
}
private Map<String, Object> getViewMap(){
return FacesContext.getCurrentInstance().getViewRoot().getViewMap();
}
}
See my class test
#Scope("singleton")
#Configuration("webappTest")
#ComponentScan
#WebAppConfiguration
#EnableTransactionManagement
#ContextConfiguration(classes = SysSampleConfig.class)
public class NotConfirmedEmailTest extends AbstractTestNGSpringContextTests
{
#Autowired
private WebApplicationContext webApplicationContext;
#Autowired
#Qualifier("chromeDriver")
private WebDriver driver;
#Qualifier("user")
#Autowired
private UserController userController;
#PostConstruct
public void init()
{
LOG.info("init ..." + webApplicationContext.toString());
}
See stacktrace
ERROR - 11:04:26 093 - org.springframework.test.context.TestContextManager.prepareTestInstance(231) - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener#549d1965] to prepare test instance [com.sys.mod.email.SysNotConfirmedEmailTest#1e0f9063]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.sys.mod.email.SysNotConfirmedEmailTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.sys.mod.person.controllers.SysClientCaptureController com.sys.mod.email.SysNotConfirmedEmailTest.clientCaptureController; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:385) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118) ~[spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) ~[spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228) ~[spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextPrepareTestInstance(AbstractTestNGSpringContextTests.java:149) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_73]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_73]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_73]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_73]
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104) [testng-6.10.jar:na]
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515) [testng-6.10.jar:na]
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:217) [testng-6.10.jar:na]
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:144) [testng-6.10.jar:na]
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:169) [testng-6.10.jar:na]
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108) [testng-6.10.jar:na]
at org.testng.TestRunner.privateRun(TestRunner.java:756) [testng-6.10.jar:na]
at org.testng.TestRunner.run(TestRunner.java:610) [testng-6.10.jar:na]
at org.testng.SuiteRunner.runTest(SuiteRunner.java:387) [testng-6.10.jar:na]
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382) [testng-6.10.jar:na]
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) [testng-6.10.jar:na]
at org.testng.SuiteRunner.run(SuiteRunner.java:289) [testng-6.10.jar:na]
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) [testng-6.10.jar:na]
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) [testng-6.10.jar:na]
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293) [testng-6.10.jar:na]
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218) [testng-6.10.jar:na]
at org.testng.TestNG.runSuites(TestNG.java:1133) [testng-6.10.jar:na]
at org.testng.TestNG.run(TestNG.java:1104) [testng-6.10.jar:na]
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126) [testng-remote.jar:na]
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152) [testng-remote.jar:na]
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57) [testng-remote.jar:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.sys.mod.person.controllers.SysClientCaptureController com.sys.mod.email.SysNotConfirmedEmailTest.clientCaptureController; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
... 31 common frames omitted
Caused by: java.lang.NullPointerException: null
at com.sys.util.SysViewScope.getViewMap(SysViewScope.java:78) ~[classes/:na]
at com.sys.util.SysViewScope.get(SysViewScope.java:24) ~[classes/:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:340) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
... 33 common frames omitted
FAILED CONFIGURATION: #BeforeClass springTestContextPrepareTestInstance
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.sys.mod.email.SysNotConfirmedEmailTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.sys.mod.person.controllers.SysClientCaptureController com.sys.mod.email.SysNotConfirmedEmailTest.clientCaptureController; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:385)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228)
at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextPrepareTestInstance(AbstractTestNGSpringContextTests.java:149)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:217)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:144)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:169)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:756)
at org.testng.TestRunner.run(TestRunner.java:610)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.sys.mod.person.controllers.SysClientCaptureController com.sys.mod.email.SysNotConfirmedEmailTest.clientCaptureController; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 31 more
Caused by: java.lang.NullPointerException
at com.sys.util.SysViewScope.getViewMap(SysViewScope.java:78)
at com.sys.util.SysViewScope.get(SysViewScope.java:24)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:340)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
... 33 more
What i'm doing for solve this problem, FacesContext.getCurrentInstance(), not return more null?

Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Collection, at table

Thia has eaten up my weekend I searched about it but their might be several problems that might be causing it, hope some one will help me out.
I am trying to create a many to many relationship via one to many and many to one relationship using third table but I am getting this error:
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Collection, at table: PoojaFirstCategory, for columns: [org.hibernate.mapping.Column(poojaPanditRelationShip)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:314) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:292) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.mapping.Property.isValid(Property.java:239) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:483) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.mapping.RootClass.validate(RootClass.java:270) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.cfg.Configuration.validate(Configuration.java:1327) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1789) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96) [hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914) [hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
... 26 more
2016/04/03 09:12:14,134 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-7) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956) [spring-context-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747) [spring-context-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) [spring-context-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383) [spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283) [spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_95]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_95]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_95]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:924) [hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899) [hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:76) [hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:286) [spring-orm-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310) [spring-orm-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
... 20 more
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Collection, at table: PoojaFirstCategory, for columns: [org.hibernate.mapping.Column(poojaPanditRelationShip)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:314) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:292) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.mapping.Property.isValid(Property.java:239) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:483) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.mapping.RootClass.validate(RootClass.java:270) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.cfg.Configuration.validate(Configuration.java:1327) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1789) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96) [hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914) [hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
... 26 more
2016/04/03 09:12:14,135 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/]] (MSC service thread 1-7) Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956) [spring-context-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747) [spring-context-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) [spring-context-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383) [spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283) [spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_95]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_95]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_95]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:924) [hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899) [hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:76) [hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:286) [spring-orm-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310) [spring-orm-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
... 20 more
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Collection, at table: PoojaFirstCategory, for columns: [org.hibernate.mapping.Column(poojaPanditRelationShip)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:314) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:292) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.mapping.Property.isValid(Property.java:239) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:483) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.mapping.RootClass.validate(RootClass.java:270) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.cfg.Configuration.validate(Configuration.java:1327) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1789) [hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96) [hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914) [hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
... 26 more
2016/04/03 09:12:14,540 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-7) Error listenerStart
2016/04/03 09:12:14,541 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-7) Context [] startup failed due to previous errors
My entities are :
#Entity
public class PoojaFirstCategory {
private Long poojaFirstCategoryId;
private String name;
private String brief;
private Set<PoojaPanditRelationShip> poojaPanditRelationShip;
public PoojaFirstCategory() {
}
public PoojaFirstCategory(String name,String brief) {
this.name = name;
this.brief = brief;
poojaPanditRelationShip = new HashSet<PoojaPanditRelationShip>();
}
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
public Long getPoojaFirstCategoryId() {
return poojaFirstCategoryId;
}
public void setPoojaFirstCategoryId(Long poojaFirstCategoryId) {
this.poojaFirstCategoryId = poojaFirstCategoryId;
}
public Set<PoojaPanditRelationShip> getPoojaPanditRelationShip() {
return poojaPanditRelationShip;
}
#OneToMany(mappedBy = "poojaFirstCategory", cascade = CascadeType.ALL)
public void setPoojaPanditRelationShip(Set<PoojaPanditRelationShip> poojaPanditRelationShip) {
this.poojaPanditRelationShip = poojaPanditRelationShip;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBrief() {
return brief;
}
public void setBrief(String brief) {
this.brief = brief;
}
}
#Entity
public class PoojaSecondCategory {
private Long poojaSecondCategoryId;
private Long TId;
private String poojaName;
private String name;
private Integer experince;
private byte[] photo;
private Integer rate;
public PoojaSecondCategory() {
}
public PoojaSecondCategory(String poojaName,String name, Integer experince, Integer rate) {
this.poojaName = poojaName;
this.name = name;
this.experince = experince;
this.rate = rate;
}
private Set<PoojaPanditRelationShip> poojaPanditRelationShip;
public Set<PoojaPanditRelationShip> getPoojaPanditRelationShip() {
return poojaPanditRelationShip;
}
#OneToMany(mappedBy = "poojaSecondCategory" ,cascade = CascadeType.ALL)
public void setPoojaPanditRelationShip(Set<PoojaPanditRelationShip> poojaPanditRelationShip) {
this.poojaPanditRelationShip = poojaPanditRelationShip;
}
public String getPoojaName() {
return poojaName;
}
public void setPoojaName(String poojaName) {
this.poojaName = poojaName;
}
public Long getTId() {
return TId;
}
public void setTId(Long tId) {
TId = tId;
}
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
public Long getPoojaSecondCategoryId() {
return poojaSecondCategoryId;
}
public void setPoojaSecondCategoryId(Long poojaSecondCategoryId) {
this.poojaSecondCategoryId = poojaSecondCategoryId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getExperince() {
return experince;
}
public void setExperince(Integer experince) {
this.experince = experince;
}
public byte[] getPhoto() {
return photo;
}
public void setPhoto(byte[] photo) {
this.photo = photo;
}
public Integer getRate() {
return rate;
}
public void setRate(Integer rate) {
this.rate = rate;
}
}
and my relationship entity is :
#Entity
public class PoojaPanditRelationShip implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private Long id;
private PoojaFirstCategory poojaFirstCategory;
private PoojaSecondCategory poojaSecondCategory;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
#Id
#ManyToOne
#JoinColumn(name = "poojaFirstCategoryId")
public PoojaFirstCategory getPoojaFirstCategory() {
return poojaFirstCategory;
}
public void setPoojaFirstCategory(PoojaFirstCategory poojaFirstCategory) {
this.poojaFirstCategory = poojaFirstCategory;
}
#Id
#ManyToOne
#JoinColumn(name = "poojaSecondCategoryId")
public PoojaSecondCategory getPoojaSecondCategory() {
return poojaSecondCategory;
}
public void setPoojaSecondCategory(PoojaSecondCategory poojaSecondCategory) {
this.poojaSecondCategory = poojaSecondCategory;
}
}
and here I am trying to populate some dummy data:
#Component
public class StartOnStartUp implements ApplicationListener<ContextRefreshedEvent> {
#Autowired
private TouristFirstCategoryRepository touristFirstCategoryRepository;
#Autowired
private TouristSecondCategoryRepository touristSecondCategoryRepository;
#Autowired
private PoojaFirstCategoryRepository poojaFirstCategoryRepository;
#Autowired
private PoojaSecondCategoryRepository poojaSecondCategoryRepository;
#Override
#Transactional
public void onApplicationEvent(ContextRefreshedEvent arg0) {
PoojaFirstCategory poojaFirstCategory = new PoojaFirstCategory("StayaNarayan","SatayNarayan Ki pooja");
PoojaSecondCategory poojaSecondCategory = new PoojaSecondCategory("StayaNarayan","Pandit Brij Bhushan",23,1000);
PoojaPanditRelationShip poojaPanditRelationShip = new PoojaPanditRelationShip();
poojaPanditRelationShip.setPoojaFirstCategory(poojaFirstCategory);
poojaPanditRelationShip.setPoojaSecondCategory(poojaSecondCategory);
poojaFirstCategory.getPoojaPanditRelationShip().add(poojaPanditRelationShip);
poojaSecondCategoryRepository.save(poojaSecondCategory);
poojaFirstCategoryRepository.save(poojaFirstCategory);
}
I am also using hibernate property to create table based on entity classes
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<!-- spring based scanning for entity classes -->
<property name="packagesToScan" value="first.varanasi.erp" />
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
You should put annotation mapping on getter (or field), not setter. So instead of this:
#OneToMany(mappedBy = "poojaFirstCategory", cascade = CascadeType.ALL)
public void setPoojaPanditRelationShip(Set<PoojaPanditRelationShip> poojaPanditRelationShip) {
this.poojaPanditRelationShip = poojaPanditRelationShip;
}
You should use this:
#OneToMany(mappedBy = "poojaFirstCategory", cascade = CascadeType.ALL)
public Set<PoojaPanditRelationShip> getPoojaPanditRelationShip() {
return poojaPanditRelationShip;
}
HTH.

Spring data cassandra - Cannot find changelog location: class path resource

I am integrating cassandra in my application and i have no clue of this exception ! i did not find any help online so posting a question here.
I followed this link
Cassandra config
#Configuration
#PropertySource(value = {"classpath:cassandra.properties"})
#EnableCassandraRepositories(basePackages = { "com.demo" })
public class CassandraConfig {
#Autowired
private Environment environment;
#Bean
public CassandraClusterFactoryBean cluster() {
CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
cluster.setContactPoints(environment.getProperty("cassandra.contactpoints"));
cluster.setPort(Integer.parseInt(environment.getProperty("cassandra.port")));
return cluster;
}
#Bean
public CassandraMappingContext mappingContext() {
return new BasicCassandraMappingContext();
}
#Bean
public CassandraConverter converter() {
return new MappingCassandraConverter(mappingContext());
}
#Bean
public CassandraSessionFactoryBean session() throws Exception {
CassandraSessionFactoryBean session = new CassandraSessionFactoryBean();
session.setCluster(cluster().getObject());
session.setKeyspaceName(environment.getProperty("cassandra.keyspace"));
session.setConverter(converter());
session.setSchemaAction(SchemaAction.NONE);
return session;
}
#Bean
public CassandraOperations cassandraTemplate() throws Exception {
return new CassandraTemplate(session().getObject());
}
}
Maven pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
</dependency>
...
cassandra.properties
cassandra.contactpoints=127.0.0.1
cassandra.port=9042
cassandra.keyspace=test
cassandra repository
public interface CustomerRepository extends CassandraRepository<Customer> {
}
casssandra entity class
#Table
public class Customer {
#PrimaryKeyColumn(name = "id",ordinal = 1,type = PrimaryKeyType.CLUSTERED)
private UUID id;
#PrimaryKeyColumn(name="user",ordinal = 0,type = PrimaryKeyType.PARTITIONED)
private String name;
private String address;
public Customer()
{
}
public Customer( UUID id, String name, String address )
{
this.id = id;
this.name = name;
this.address = address;
}
#Override
public String toString()
{
return String.format("Customer[id=%s, name='%s', address='%s']", this.id, this.name, this.address);
}
}
This is the error when i run the main class :
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot find changelog location: class path resource [db/changelog/db.changelog-master.yaml] (please add changelog or check your Liquibase configuration)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
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.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
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.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
Caused by: java.lang.IllegalStateException: Cannot find changelog location: class path resource [db/changelog/db.changelog-master.yaml] (please add changelog or check your Liquibase configuration)
at org.springframework.util.Assert.state(Assert.java:385)
at org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration.checkChangelogExists(LiquibaseAutoConfiguration.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:349)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:300)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
... 28 more
Thanks in advance !

Can't Register MBean via Spring

I am trying to export an annotated MBean using Spring. But getting the following exception (when trying to deploy on tomcat7):
javax.management.MalformedObjectNameException: Key properties cannot be empty
Here is my JmxTestBean class:
package com.i2gether.service.jmx;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedOperationParameter;
import org.springframework.jmx.export.annotation.ManagedOperationParameters;
import org.springframework.jmx.export.annotation.ManagedResource;
#ManagedResource(description = "My Managed Bean")
public class JmxTestBean {
private String name;
private int age;
#ManagedAttribute(description = "The Age Attribute")
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
#ManagedAttribute(description = "The Name Attribute")
public void setName(String name) {
this.name = name;
}
#ManagedAttribute(defaultValue = "foo")
public String getName() {
return name;
}
#ManagedOperation(description = "Add two numbers")
#ManagedOperationParameters({ #ManagedOperationParameter(name = "x", description = "The first number"),
#ManagedOperationParameter(name = "y", description = "The second number") })
public int add(int x, int y) {
return x + y;
}
public void dontExposeMe() {
throw new RuntimeException();
}
}
And here is the relevant portion from my spring context configuration:
<beans xmlns="http://www.springframework.org/schema/beans" ...>
<context:component-scan base-package="com.i2gether.service" />
<context:mbean-export />
<bean id="serviceLayerExporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
<!-- notice how no beans are explicitly configured here -->
<property name="autodetect" value="true" />
<property name="assembler" ref="assembler" />
</bean>
<bean id="testBean" class="com.i2gether.service.jmx.JmxTestBean">
<property name="name" value="TEST" />
<property name="age" value="100" />
</bean>
<bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
<property name="attributeSource">
<bean class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />
</property>
</bean>
</beans>
Finally, the error log looks like this:
11:52:25.794 [pool-2-thread-1] ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceLayerExporter' defined in class path resource [appcontext.xml]: Invocation of init method failed; nested exception is org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [com.i2gether.service.jmx.JmxTestBean#6e6c28f7] with key 'testBean'; nested exception is javax.management.MalformedObjectNameException: Key properties cannot be empty
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) ~[spring-web-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) ~[spring-web-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) ~[spring-web-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779) ~[catalina.jar:7.0.27]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273) ~[catalina.jar:7.0.27]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[catalina.jar:7.0.27]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895) ~[catalina.jar:7.0.27]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871) ~[catalina.jar:7.0.27]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615) ~[catalina.jar:7.0.27]
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:649) ~[catalina.jar:7.0.27]
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1585) ~[catalina.jar:7.0.27]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) ~[na:1.7.0_25]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) ~[na:1.7.0_25]
at java.util.concurrent.FutureTask.run(FutureTask.java:166) ~[na:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_25]
at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
Caused by: org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [com.i2gether.service.jmx.JmxTestBean#6e6c28f7] with key 'testBean'; nested exception is javax.management.MalformedObjectNameException: Key properties cannot be empty
at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:610) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:535) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.jmx.export.MBeanExporter.afterPropertiesSet(MBeanExporter.java:417) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
... 26 common frames omitted
Caused by: javax.management.MalformedObjectNameException: Key properties cannot be empty
at javax.management.ObjectName.construct(ObjectName.java:483) ~[na:1.7.0_25]
at javax.management.ObjectName.<init>(ObjectName.java:1382) ~[na:1.7.0_25]
at javax.management.ObjectName.getInstance(ObjectName.java:1273) ~[na:1.7.0_25]
at org.springframework.jmx.support.ObjectNameManager.getInstance(ObjectNameManager.java:62) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.jmx.export.naming.KeyNamingStrategy.getObjectName(KeyNamingStrategy.java:142) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.jmx.export.MBeanExporter.getObjectName(MBeanExporter.java:736) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:639) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:600) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
... 30 common frames omitted
Can someone please point me to what wrong I am doing?
You should specify objectName attribute for #ManagedResource annotation.
Here you can find detailed description by #Dude Spring MBeanExporter - giving name to MBean

Resources