So I have a project I want to start work with. The senior developer sent me a zip package of the project and database.sql file for initializing the local database for me to just launch the project. But we are facing the error.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring/spring-database.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution
All entities are exactly the same as in the local database. I have changed the XML file config to match my password and URL. Spend 2 days trying to run the project. Will appreciate any help. Please feel free to ask any questions.
<!-- Configure the entity manager factory bean -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
<!-- Set JPA properties -->
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.ProgressDialect</prop>
</props>
</property>
<property name="packagesToScan" value="nl.impressie.grazer.hibernate" />
</bean>
Sounds like hibernate is failing to initialize due to a failure to connect to the DB.
Are you sure you have a Postgresql DB running? Is Spring configured correctly to interface with that DB? (i.e. is the host, port, databaseschema, username and password set?)
If this is a new project, you shouldn't be using any of this XML configuration at all. Instead, create a template project at https://start.spring.io that includes the JPA starter, set your spring.datasource.url, and be running in 2 minutes.
Related
New to hibernate and the migration process from Hibernate4 to Hibernate5.
The codebase I'm working with previously used Hibernate4, and we had our naming strategy setup in Hibernate.cfg.xml as such:
<bean id="namingStrategy"
class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
<property name="staticField">
<value>org.hibernate.cfg.ImprovedNamingStrategy.INSTANCE</value>
</property>
</bean>
with the bean then defined in a property tag within our sessionFactory definition. I'm trying to figure out how to do this in Hibernate5.
I read that Hibernate did away with the ImprovedNamingStrategy and went with either PhysicalNamingStrategy or ImplicitNamingStrategy, and that for my purpose I should be using Implicit. I've tried swapping out the strategy names, but that's causing runtime errors as it can't find the class.
<bean id="namingStrategy"
class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
<property name="staticField">
<value>org.hibernate.cfg.ImplicitNamingStrategy.INSTANCE</value>
</property>
</bean>
Any help would be appreciated.
I am trying to use Hikari connection pooling for my spring based app using xml based bean configuration. Below is my Hikari config bean and I am using the Db2 as my database.
<bean id="HikariConfig_UId_Primary" class="com.zaxxer.hikari.HikariConfig">
<property name="poolName" value="uidPrimaryCP" />
<property name="connectionTestQuery" value="select 1 from sysibm.systables fetch first row only with UR" />
<property name="dataSourceClassName" value="${Jdbc_DataSourceClassName}" />
<property name="maximumPoolSize" value="${Jdbc_MaxPoolSize}"/>
<property name="idleTimeout" value="${Jdbc_IdleTimeOut}" />
<property name="maxLifetime" value="${Jdbc_MaxLifeTime}" />
<property name="connectionTimeout" value="${Jdbc_ConnTimeOut}" />
<property name="dataSourceProperties">
<props>
<prop key="url">${Jdbc_UID_Primary}</prop>
<prop key="user">${Jdbc_UserId}</prop>
<prop key="password">${Jdbc_Password}</prop>
</props>
</property>
</bean>
<bean id="UID_Primary_DataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<constructor-arg ref="HikariConfig_UId_Primary" />
</bean>
It failing to register the bean, saying the database url property - url does not exists on target class com.ibm.db2.jcc.DB2SimpleDataSource.
below is the complete stack trace..
com.ibm.ws.webcontainer.webapp.WebApp notifyServletContextCreated SRVE0283E: Exception caught while initializing context: {0}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UID_Primary_DataSource' defined in class path resource [config/SpringDbContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.zaxxer.hikari.HikariDataSource]: Constructor threw exception; nested exception is java.lang.RuntimeException: Property url does not exist on target class com.ibm.db2.jcc.DB2SimpleDataSource
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:278)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.deere.u90.iafservice.unifieduser.application.ApplicationRegistry.loadSpringLdapContext(ApplicationRegistry.java:
any help is greatly appreciated..
thanks..
I've connected to Hikari using spring boot but not with xml configuration. See my post here
I think, adding up below property should fix error.
<property name="jdbcUrl" value="" />
<property name="username" value="" />
<property name="password" value="" />
You seem to have several things wrong. You didn't post the value of variable ${Jdbc_DataSourceClassName} be it appears to resolve to DB2SimpleDataSource at runtime. Per this IBM KnowledgeCenter topic, that datasource is not poolable and since you started the post with "I am trying to use Hikari connection pooling", I'm assuming you want a poolable DS like com.ibm.db2.jcc.DB2ConnectionPoolDataSource as described here.
The second problem is that the DB2 Datasource classes don't support a url property, only the DB2 DriverManager interface supports it. The KC topic for the abstract base of the DB2 data source classes, DB2BaseDataSource, says
You can set all properties on a DataSource or in the url parameter in
a DriverManager.getConnection call.
url is not one of the listed properties, so you're going to need to establish the connection to the dataasource using the hostname, port, etc properties
Inserting values in Oracle 11g via JdbcTemplate-OracleDataSource injected via Spring config file. Transactions are done via #Transactional managed by DataSourceTransactionManager.
Question 1) is how to set the autocommit value to false through the Spring config file.
Tried with :
<property name="autoCommit" value="false" />
<property name="defaultAutoCommit" value="false" />
Both are giving error:
org.springframework.beans.NotWritablePropertyException: Invalid property 'defaultAutoCommit' of bean class [oracle.jdbc.pool.OracleDataSource]
Thanks in advance.
These properties won't work because there is no setAutoCommit() or setDefaultAutoCommit() methods in OracleDataSource.
What there is there and we can use instead is OracleDataSource#setConnectionProperties() that is has Properties as argument and we can define on the fly in the OracleDataSource Spring bean by adding property:
<property name="connectionProperties">
<props merge="default">
<prop key="AutoCommit">false</prop>
</props>
</property>
I'm trying to config datasource in Spring 2.5.6.
My database is oracle 11g and jdbc driver is ojdbc6.
The following is my configuration:
<bean id="databaseConnectionPool" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close">
<property name="connectionCachingEnabled" value="true"/>
<property name="URL"><value>${jdbc.dburl}</value></property>
<property name="connectionCacheName" value="PSSMST"/>
<property name="user"><value>${jdbc.dbusername}</value></property>
<property name="password"><value>${jdbc.dbpassword}</value></property>
<property name="maxStatements" value="75"/>
<property name="connectionCacheProperties">
<props merge="default">
<prop key="MinLimit">20</prop>
<prop key="MaxLimit">150</prop>
<prop key="InitialLimit">20</prop>
</props>
</property>
</bean>
But when the Tomcat server starts up, I get this message:
Invalid property 'connectionCachingEnabled' of bean class
[oracle.jdbc.pool.OracleDataSource]: Bean property
'connectionCachingEnabled' is not writable or has an invalid setter
method. Does the parameter type of the setter match the return type of
the getter?
That really makes me upset. I checked the OracleDataSource class, of course, the setConnectionCachingEnabled method exists.
Does anybody know how to resolve this?
The probable reason is that you are using an older version of ODBC than intended. Please check lib folder of your application and also check lib folder of Tomcat.
I think i already know what is the problem. i keep getting this error
org.springframework.beans.factory.BeanCreationException:
Could not autowire method: public void proTurism.DAO.AbstractDAO.setSession(org.hibernate.SessionFactory); nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
The problem shoulb be of 2 uncompatible ASM versions one using spring and one hibernate. i have hibernate ASM(unknown version packed in netbeans 7.1) and spring ASM(3.0.6). but i havent found any solution on how to get one asm or anything to get it working in glassfish with netbeans.
my applicationcontext.xml
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="proTurism"/>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
That's a tough dependency problem. You can only solve it if your two libraries (hibernate and spring) depend either on the same version of ASM, or on non-conflicting versions of ASM in terms of the functionality used. If that is not the case, upgrade/downgrade spring/hibernate until it works.
If using Maven, it will automatically show you which artifact requires which versions of its dependencies and it will be easier to trace and play with. Even if not using maven, you can still check the pom definitions of hibernate and spring to see which versions of asm they work with.