I'm getting error while integrating spring and hibernate - spring

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentManager' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'studentDao' while setting bean property 'studentDao';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentDao' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Initialization of bean failed;
nested exception is java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
default-lazy-init="true">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/Java2all"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>Student.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
<bean id="studentDao" class="com.dao.impl.StudentDaoHibernate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="studentManager" class="com.manager.StudentManagerImpl">
<property name="studentDao" ref="studentDao" />
</bean>
</beans>
student.xml
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name ="com.springhibnernate.Student" table="Student">
<id name="id" type="java.lang.Long">
<generator class="native"/>
</id>
<property name="name" type="string">
<column name="name" length="40"/>
</property>
</class>
</hibernate-mapping>

There is a good chance you are missing "JTA-X.X.jar" in your classpath.

Related

Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'xaDataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xaDataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'xaDataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'driverClassName' of bean class [org.postgresql.xa.PGXADataSource]: Bean property 'driverClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:829)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1091)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1980)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
<?xml version="1.0" encoding="UTF-8"?>
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">
<bean id="requestHandler" class="org.dejach.marketServer.requesthandler.RequestHandler" init-method="init">
<property name="factory" ref="marketApiFactory"></property>
</bean>
<bean id="RequestProcessor" class="org.dejach.marketServer.processor.RequestProcessor">
<property name="handler" ref="requestHandler" />
</bean>
<bean id="marketApiFactory" class="org.dejach.marketServer.processor.MarketApiFactory">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>WEB-INF/marketApi.properties</value>
</property>
<property name="nullValue" value="#null" />
</bean>
<bean id="properties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location" value="WEB-INF/marketApi.properties" />
</bean>
<bean id="dataSource" class="org.postgresql.xa.PGXADataSource">
<!-- <property name="pinGlobalTxToPhysicalConnection" value="true" /> -->
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="${jdbcUrl}" />
<property name="user" value="${username}" />
<property name="password" value="${password}" />
</bean>
<!-- configure an Atomikos JTA-aware datasource -->
<bean id="xaDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="xaDatasource" />
<property name="xaDataSource" ref="dataSource" />
<property name="poolSize" value="${poolSize}" />
</bean>
<!-- http://fogbugz.atomikos.com/default.asp?community.6.702.5 -->
<bean id="userTransactionService" class="com.atomikos.icatch.config.UserTransactionServiceImp"
init-method="init" destroy-method="shutdownForce">
<constructor-arg>
<props>
<prop key="com.atomikos.icatch.log_base_name">${com.atomikos.icatch.log_base_name}</prop>
<prop key="com.atomikos.icatch.log_base_dir">${com.atomikos.icatch.log_base_dir}</prop>
<prop key="com.atomikos.icatch.max_timeout">3600000</prop>
</props>
</constructor-arg>
</bean>
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close" depends-on="userTransactionService">
<property name="forceShutdown" value="false" />
<property name="startupTransactionService" value="true" />
</bean>
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.J2eeUserTransaction">
<property name="transactionTimeout" value="${transactionTimeout}" />
</bean>
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager"
depends-on="atomikosTransactionManager,atomikosUserTransaction">
<property name="transactionManager" ref="atomikosTransactionManager" />
<property name="userTransaction" ref="atomikosUserTransaction" />
<property name="allowCustomIsolationLevels" value="true" />
</bean>
<bean id="jpaVendor"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="${showSql}" />
<property name="databasePlatform" value="${databasePlatform}" />
<property name="generateDdl" value="${generateDdl}" />
<property name="database" value="${database}" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="xaDataSource" />
<property name="packagesToScan" value="${marketPackage}" />
<property name="jpaVendorAdapter" ref="jpaVendor" />
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
</props>
</property>
</bean>
username=postgres
password=$$$$$$$
hibernate.hbm2ddl.auto=create
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
# package scan for entities
marketPackage=org.dejach
transactionTimeout=300
showSql=true
#databasePlatform=org.hibernate.dialect.MySQL5InnoDBDialect
databasePlatform=org.hibernate.dialect.PostgreSQLDialect
#database=org.springframework.orm.jpa.vendor.Database.MYSQL
#database=MYSQL
database=POSTGRESQL
generateDdl=false
poolSize=30
#XA datasource
#XADataSource=${mysqlDataSource}
XADataSource=${postgresqlDataSource}
#mysqlDataSource=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
postgresqlDataSource=org.postgresql.xa.PGXADataSource
H2xadatasource=org.h2.jdbcx.JdbcDataSource
postgresqlUrl = jdbc:postgresql://localhost:5432/ethiopianMarketdb
H2url=jdbc:h2:mem:testdb;MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
jdbcUrl=${postgresqlUrl}
blobFieldName=xmlData
#Atomikus properties
#see http://www.atomikos.com/Documentation/JtaProperties com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory
com.atomikos.icatch.console_file_name
#Specifies the console log level. Defaults to WARN. Should be one of: WARN, INFO or DEBUG.
com.atomikos.icatch.log_base_name=tmlog
com.atomikos.icatch.log_base_dir=target
#com.atomikos.icatch.log_base_dir=/transactionLogs/
#com.atomikos.icatch.tm_unique_name=
com.atomikos.icatch.max_timeout=3600000
I don't see a setter setDriverClassName(..) in following class
https://jdbc.postgresql.org/documentation/publicapi/org/postgresql/xa/PGXADataSource.html
So, it make sense to remove following property from xaDataSource and try once again
<property name="driverClassName" value="org.postgresql.Driver" />
BTW, I don't any setUrl either, so you should review the logic of creating your bean.
Here is the list of available setters:
setCompatible
setDatabaseName
setLoginTimeout
setLogLevel
setLogWriter
setPassword
setPortNumber
setPrepareThreshold
setProtocolVersion
setServerName
setSocketTimeout
setSsl
setSslfactory
setTcpKeepAlive
setUnknownLength
setUser
writeBaseObject

No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 0:

I use Spring and Spring data for the system that I am developing. The following is the config file.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<context:component-scan base-package="co.infovilla.vendor" />
<context:component-scan base-package="co.infovilla.vendor.repositories" />
<context:component-scan base-package="co.infovilla.vendor.services" />
<jpa:repositories base-package="co.infovilla.vendor.repositories" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/vendordb" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
</beans>
When I access it using the following code I get exceptions.
public static void main(String[] args) {
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext("application-context.xml");
ProductService productService = ctx.getBean(ProductService.class);
Product product = new Product();
product.setName("Phone");
product.setPrice(500000);
productService.save(product);
}
The exceptions are:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productRepository': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 0:
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:306)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at co.infovilla.vendor.main.App.main(App.java:11)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productRepository': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 0:
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:343)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:442)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:550)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:155)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:92)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303)
... 13 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 0:
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:538)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:497)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:659)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:632)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:164)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:92)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:340)
... 26 more
As far as I know I don't need to configure the entity manager factory when using JPA the way I am using it. What might have gone wrong?
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
This isn't configuring an EntityManagerFactory but a SessionFactory. To configure an EntityManagerFactory use a LocalContainerEntityManagerFactoryBean. See here for more information on how to setup JPA with Spring.
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="datasource"/>
<property name="packagesToScan" value="[package-containing-your-#Entities]"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</bean>
</property>
</bean>
You probably also want to use the specific MySQL5InnoDBDialect instead of the plain MysqlDialect.

Spring data 1.6.0 GA cannot find entity manager factory bean by custom id

I have found the strange behavior of Spring data 1.6.0 (downgraded version 1.5.2 does not have this problem). It seems that this version strictly demands the id of entity manager factory bean to be "entityManagerFactory". If not, this error appears when running TestNG test:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMapppingContext': Cannot create inner bean '(inner bean)#36b87404' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#36b87404': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' is defined
My configuration is:
<!-- ************************************************************** -->
<!-- Database configuration -->
<!-- ************************************************************** -->
<!-- Entity manager factory bean -->
<bean id="entityManagerFactoryCustomId"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="test-system" />
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<array>
<value>${pds.db.scan.model}</value>
</array>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">${jdbc.showsql}</prop>
<prop key="hibernate.format_sql">${jdb.formatsql}</prop>
<prop key="hibernate.hbm2ddl.auto">${jdbc.hbm2ddl.auto}</prop>
</props>
</property>
</bean>
<!-- C3P0 connection pool -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<!-- Connection properties -->
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!-- Pool properties -->
<property name="minPoolSize" value="${pool.minsize}" />
<property name="maxPoolSize" value="${pool.maxsize}" />
<property name="initialPoolSize" value="${pool.initialPoolSize}" />
<property name="maxStatements" value="${pool.maxstatements}" />
<property name="acquireIncrement" value="${pool.acquireincrement}" />
<property name="preferredTestQuery" value="${jdbc.check}" />
<property name="numHelperThreads" value="${pool.threads}" />
</bean>
<!-- JPA transaction manager -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactoryCustomId" />
</bean>
<!-- Activate Spring Data JPA repository support -->
<jpa:repositories base-package="pds.archiva.db.repository" />
</code>
Is it a bug in Spring Data JPA or am I doing something wrong ? Tested on windows java 64bit 7u55 with following versions:
spring.framework.version = 4.0.5.RELEASE
spring.security.version = 3.2.4.RELEASE
spring.data-jpa.version = 1.6.0.RELEASE
As I have written, the same test works with only changing spring.data-jpa.version = 1.5.2.RELEASE ... or change id of bean to "entityManagerFactory" instead of "entityManagerFactoryCustomId".
Just added #StéphaneNicoll answer:
set the entity manager explicitly then (see entity-manager-factory-refelement in jpa:repositories . Looks like the documentation might be outdated.

org.springframework.beans.factory.BeanCreationException: Error while mapping Spring with context datasource

This is my spring context file
<!-- <context:property-placeholder location="classpath:jdbc.properties" />-->
<context:component-scan base-package="com.max.premcalc" />
<tx:annotation-driven transaction-manager="hibernateTransactionManager" />
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/inquizzitiveds"/>
<!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${database.driver}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.user}" />
<property name="password" value="${database.password}" />
</bean> -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.max.premcalc.domain.PremiumCalc</value>
<value>com.max.premcalc.domain.Inputparam</value>
<value>com.max.premcalc.domain.RiderInput</value>
<value>com.max.premcalc.domain.Rider</value>
<value>com.max.premcalc.domain.Product</value>
<value>com.max.premcalc.domain.Products</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
</props>
</property>
</bean>
<bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="MainController" class="com.max.premcalc.controller.MainController" />
<bean id = "calcDao" class="com.max.premcalc.dao.CalcDaoImpl"/>
<bean id = "calcService" class="com.max.premcalc.service.CalcServiceImpl"/>
<bean id = "inputparam" class = "com.max.premcalc.domain.Inputparam"/>
But I'm getting this error :
Injection of autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private
com.max.premcalc.service.CalcService com.max.premcalc.controller.MainController.calcService; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'calcServiceImpl': Injection
of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: com.max.premcalc.dao.CalcDao com.max.premcalc.service.CalcServiceImpl.calcDao; nested
exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao':
Injection of autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void
com.max.premcalc.dao.CalcDaoImpl.setSessionFactory(org.hibernate.SessionFactory); nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in
ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is
org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
You need to set the property
hibernate.dialect
In the hibernate (persistence.xml or bean declaration) configuration, the value depends on your database, for example:
Postgres: org.hibernate.dialect.PostgreSQL82Dialect
Oracle: org.hibernate.dialect.Oracle10gDialect
All posible options are listen here
For example, a sample persistence.xml looks like:
<persistence-unit>
...
<properties>
...
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
...
</properties>
</persistence-unit>
Please, check if your properties file have the key hibernate-dialect
The stacktrace is pretty clear
org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
Apparently hibernate cannot use the metadata to retrieve the type of database to use, as a result one must configure the hibernate dialect explicitly.

MalformedParameterizedTypeException when running Mybatis App

here's the stacktrace:
Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
I used the libraries that came w/ the mybatis-spring 1.1.1 and I added the spring-web-3.1.1.RELEASE.jar. My IDE is JDeveloper 11.1.2.1.0. here's the contents of WEB-INF/lib
aopalliance-1.0.jar
commons-logging-1.1.1.jar
jettison-1.1.jar
mybatis-3.1.1.jar
mybatis-spring-1.1.1.jar
mybatis-spring-1.1.1-javadoc.jar
mybatis-spring-1.1.1-sources.jar
spring-aop-3.1.1.RELEASE.jar
spring-asm-3.1.1.RELEASE.jar
spring-batch-core-2.1.8.RELEASE.jar
spring-batch-infrastructure-2.1.8.RELEASE.jar
spring-beans-3.1.1.RELEASE.jar
spring-context-3.1.1.RELEASE.jar
spring-core-3.1.1.RELEASE.jar
spring-expression-3.1.1.RELEASE.jar
spring-jdbc-3.1.1.RELEASE.jar
spring-tx-3.1.1.RELEASE.jar
spring-web-3.1.1.RELEASE.jar
xpp3_min-1.1.4c.jar
xstream-1.3.jar
here's the contents of applicationContext.xml
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${driverClassName}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="ph.com.aub.util"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="ph.com.aub.mappers" />
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:jdbc.properties</value>
</property>
</bean>
I think you're using wrong libs: you should use mybatis-3.1.0
spring-mybatis-integration

Resources