Issues integrating spring and Hibernate in play

304 views
Skip to first unread message

viiveek sankar

unread,
Feb 16, 2014, 6:35:25 PM2/16/14
to play-fr...@googlegroups.com
Hi All,
 I have been trying to integrate dependency injection using spring  and JPA hibernate integration . I  was able to find an example in github and have been following that 

 I am getting a bean creation exception. I have been trying to debug without  much success 

BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class com.taj.configs.DataConfig: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.persistence.EntityManagerFactory com.taj.configs.DataConfig.entityManagerFactory()] threw exception; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory



Am I missing any configs?

James Ward

unread,
Feb 16, 2014, 6:54:12 PM2/16/14
to play-fr...@googlegroups.com
That code is probably pretty out-dated. I'd recommend the Play + Java +
Spring Activator template instead:
http://typesafe.com/activator/template/play-java-spring

-James
> --
> You received this message because you are subscribed to the Google
> Groups "play-framework" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to play-framewor...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

viiveek sankar

unread,
Feb 16, 2014, 7:12:21 PM2/16/14
to play-fr...@googlegroups.com
The code looks the same , the only difference is the hibernate version. I updated that , but still i am getting the same error . DO i need to define the  db credentials anywhere other than application conf . ALso the only change in my code is the package names 

viiveek sankar

unread,
Feb 16, 2014, 7:18:06 PM2/16/14
to play-fr...@googlegroups.com
Also, From the  below stack trace, its asking for a hibernate dialect to be set . Where do i set it . Sice there is no persistence.xml here , do i set that in application conf.

lay.api.UnexpectedException: Unexpected exception[BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class com.taj.configs.DataConfig: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.persistence.EntityManagerFactory com.taj.configs.DataConfig.entityManagerFactory()] threw exception; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:148) ~[play_2.10.jar:2.2.1]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:112) ~[play_2.10.jar:2.2.1]
at scala.Option.map(Option.scala:145) ~[scala-library.jar:na]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:112) ~[play_2.10.jar:2.2.1]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:110) ~[play_2.10.jar:2.2.1]
at scala.util.Success.flatMap(Try.scala:200) ~[scala-library.jar:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class com.taj.configs.DataConfig: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.persistence.EntityManagerFactory com.taj.configs.DataConfig.entityManagerFactory()] threw exception; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:592) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.persistence.EntityManagerFactory com.taj.configs.DataConfig.entityManagerFactory()] threw exception; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915) ~[hibernate-entitymanager-4.1.9.Final.jar:4.1.9.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890) ~[hibernate-entitymanager-4.1.9.Final.jar:4.1.9.Final]
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74) ~[hibernate-entitymanager-4.1.9.Final.jar:4.1.9.Final]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:318) ~[spring-orm-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) ~[spring-orm-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at com.taj.configs.DataConfig.entityManagerFactory(DataConfig.java:37) ~[na:na]
Caused by: org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:97) ~[hibernate-core-4.1.9.Final.jar:4.1.9.Final]
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:67) ~[hibernate-core-4.1.9.Final.jar:4.1.9.Final]
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:170) ~[hibernate-core-4.1.9.Final.jar:4.1.9.Final]
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75) ~[hibernate-core-4.1.9.Final.jar:4.1.9.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159) ~[hibernate-core-4.1.9.Final.jar:4.1.9.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131) ~[hibernate-core-4.1.9.Final.jar:4.1.9.Final]

James Ward

unread,
Feb 16, 2014, 7:28:46 PM2/16/14
to play-fr...@googlegroups.com
It looks like it can't make the DB connection. "Connection cannot be
null" indicates that it was null for some reason. But you'd need to get
a error / stacktrace for the connection failure to figure that out.

-James
> <https://groups.google.com/groups/opt_out>.

viiveek sankar

unread,
Feb 16, 2014, 7:32:52 PM2/16/14
to play-fr...@googlegroups.com
thats what i was looking into. when i try with a normal db insert statement the connection works fine . i am able to get the datasource too. DO i need the persistance xml in my code base  

viiveek sankar

unread,
Feb 16, 2014, 7:38:31 PM2/16/14
to play-fr...@googlegroups.com
This si probably one of the stupid mistakes. I had to sett eh username  and password in Data config class while creating a datasource . That was the issue 

Vahid Zoghi

unread,
May 6, 2014, 9:21:52 AM5/6/14
to play-fr...@googlegroups.com
From the stack trace I see that you are using spring 4. I thought you can't use spring 4  with play because play is internally dependent on spring 3.
Did you manage to make the code work?
I have a related question here
Reply all
Reply to author
Forward
0 new messages