If you are trying to setup your project/ or adding dependency for hibernate 4 then you might face this error in your server logs.
Stack-trace will be looking like this:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.howtodoinjava.dao.EmployeeDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/employee-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'configurationClass' of bean class [org.springframework.orm.hibernate4.LocalSessionFactoryBean]: Bean property 'configurationClass' 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.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 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.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:912) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:855) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489) ... 38 more Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.howtodoinjava.dao.EmployeeDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/employee-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'configurationClass' of bean class [org.springframework.orm.hibernate4.LocalSessionFactoryBean]: Bean property 'configurationClass' 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.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286) ... 49 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/employee-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'configurationClass' of bean class [org.springframework.orm.hibernate4.LocalSessionFactoryBean]: Bean property 'configurationClass' 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.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1453) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1158) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 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.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:912) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:855) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489) ... 51 more Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'configurationClass' of bean class [org.springframework.orm.hibernate4.LocalSessionFactoryBean]: Bean property 'configurationClass' 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.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1042) at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:902) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1450) ... 62 more
Solution:
If you have anything like below declaraions in your hibernate configuration for “sessionFactory” then remove it.
<property name="configurationClass"> <value>org.hibernate.cfg.AnnotationConfiguration</value> </property>
OR
<property name="configurationClass"> <value>org.hibernate.cfg.Configuration</value> </property>
Once you will remove above declaration from “sessionFactory”, you will not see this problem again. This was valid till hibernate 3, but not in hibernate 4.
A complete usage of this solution can be looked at: Spring 3 + Hibernate Integration
Happy Learning !!
I am new to Hibernate, I have a Problem,
How to resolve the Exception “com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection”?
my application uses Hibernate. I am working on an ITS(Intelligent Transport System) So here every 10 seconds I have track the position(latitude, longitude) of bus. I call a ajax method every 10 sec which makes request to servlet. My application works fine for some time period, after that it shows error as ,
org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:160)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473)
at com.aurodisplay.its.DAO.FetchVehicleDetails.getAllVehicleDetails(FetchVehicleDetails.java:25)
at com.aurodisplay.its.ajax.RealTimeMoniotring.doPost(RealTimeMoniotring.java:81)
at com.aurodisplay.its.ajax.RealTimeMoniotring.doGet(RealTimeMoniotring.java:42)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
and
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: “Too many connections”
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1136)
I am not getting how to resolve it. I searched many resource and found that it is about managing connection pool in hibernate configuration file.
So here is my Hiberenate configuration file.
com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/bus_serverdb
root
root
1
org.hibernate.dialect.MySQLDialect
org.hibernate.cache.NoCacheProvider
true
<!– create –>
Can any one tell me what are the changes I have to do and why?
I am not sure why this exception is happening to your application but “Too many connections” usually suggest two things:
1) No. of connections in pool needs to be increased to cater application’s genuine needs
2) Your code is faulty and does not close the connections some of the times. I will suggest you to close the connections in finally blocks if you are not doing it already; AND debug the application to see if some exceptions are happening before actually closing the connections.
Here is my sample code,
Session sessio = HibernateSession.getHibernateSession();
Transaction transaction = sessio.beginTransaction();
try {
//coding stuff.
}
catch (Exception e) {
if (transaction!=null) transaction.rollback();
e.printStackTrace();
} finally {
sessio.close();
}
Here everything works fine only for some particular time period.
Is it possible to change LocalSessionFactoryBean’s dataSource dynamically?
I have defined it correclty in spring’s configuration file, and there is tied TransactionManager, TransactionProxyFactoryBean, and some Dao’s to it, and i need to copy rows from one datasource to another.
The interesting point is, that we define that destination datasource runtime, and so i cannon’t define it to configuration file.
I tried get LocalSessionFactoryBean from ApplicationContext by getBean(String) method, but it returned SessionFactory, where i cannon’t change datasource..
Try to override afterPropertiesSet() from LocalSessionFactoryBean. afterPropertiesSet() method gets called every time a DAO ojbect uses the LocalSessionFactoryBean. The afterPropertiesSet() method loads the Hibernate Configuration details.
This stackoverflow thread is also worth reading: https://stackoverflow.com/questions/16213573/setting-up-a-multitenantconnectionprovider-using-hibernate-4-2-and-spring-3-1-1
As per my requirement i need to create Excel Report. In that report some cell should have formula. I tried to set formula for particular cell like below i got org.apache.poi.ss.formula.FormulaParser.parse Exception in line no 3. Kindly help me on this
1 .String ref = (char)(‘E’ ) + “10:” + (char)(‘I’) + “10”;
2. dataCell.setCellType(Cell.CELL_TYPE_FORMULA);
3 .dataCell.setCellFormula(“SUM(” + ref + “)”);
Full Error Log:
javax.el.ELException: java.lang.NoSuchMethodError: org.apache.poi.ss.formula.FormulaParser.parse(Ljava/lang/String;Lorg/apache/poi/ss/formula/FormulaParsingWorkbook;II)[Lorg/apache/poi/ss/formula/ptg/Ptg;
at com.sun.el.parser.AstValue.invoke(Unknown Source)
at com.sun.el.MethodExpressionImpl.invoke(Unknown Source)
at org.apache.myfaces.trinidadinternal.taglib.listener.FileDownloadActionListener.processAction(FileDownloadActionListener.java:121)
at oracle.adfinternal.view.faces.event.rich.FileDownloadActionListener.processAction(FileDownloadActionListener.java:77)
……………
Caused by: java.lang.NoSuchMethodError: org.apache.poi.ss.formula.FormulaParser.parse(Ljava/lang/String;Lorg/apache/poi/ss/formula/FormulaParsingWorkbook;II)[Lorg/apache/poi/ss/formula/ptg/Ptg;
at org.apache.poi.xssf.usermodel.XSSFCell.setFormula(XSSFCell.java:439)
at org.apache.poi.xssf.usermodel.XSSFCell.setCellFormula(XSSFCell.java:419)
at com.dev.reports.ExcelReport.java.populateData(ExcelReport.java:178)
at com.dev.reports.ExcelReport.java.populateDataToWorkBook(ExcelReport.java:132)
Really hard to solve without context. General way is:
String strFormula= "SUM(A1:A10)";
cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
cell.setCellFormula(strFormula);
Now why are you using “char” with E and i. What are the values you are trying to sum?