Hello Everyone,
I'm new to hibernate, I was able to set up Hibernate successfully as per the instructions in the tutorial on this site.
Now, instead of HSQL DB I'm using MySQL.
I'm able to connect to the database successfully with plain old JDBC as well as with Hibernate.
But, when I try to call a test method to store data into a table, I get
java.lang.ExceptionInInitializerError
com.forbes.finapps.util.HibernateUtil.<clinit>(HibernateUtil.java:22)
I did search on Google for possible solutions but didn't find any so far.
Any help is appreciated.
Hibernate version: 3.2.2
Mapping documents:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://192.168.1.xxx:3306/someapp</property>
<property name="connection.username">someapp</property>
<property name="connection.password">someapp</property>
<!-- JDBC connection pool (use the built-in) -->
<!-- TODO: Configure this for production -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!--
<property name="hbm2ddl.auto">update</property>
-->
<!-- Example -->
<!--
<mapping resource="events/Event.hbm.xml"/>
-->
<mapping resource="com/forbes/finapps/ibes/beans/identification/IbesIdentification.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Code between sessionFactory.openSession() and session.close():Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
IbesIdentification ibesIdentification;
Iterator<IbesIdentification> it = ibesIdentificationList.iterator();
while (it.hasNext()) {
ibesIdentification = it.next();
session.save(ibesIdentification);
}
session.getTransaction().commit();
Full stack trace of any exception that occurs:
Error occured first time on loading JSP page:
java.lang.ExceptionInInitializerError
com.forbes.finapps.util.HibernateUtil.<clinit>(HibernateUtil.java:22)
com.forbes.finapps.ibes.beans.identification.IbesIdentificationManager.createAndStoreIbesIdentification(IbesIdentificationManager.java:106)
com.forbes.finapps.ibes.beans.identification.IbesIdentificationManager.generateDummyIdentificationRecords(IbesIdentificationManager.java:92)
org.apache.jsp.jsp.test.StoreIbesIdentification_jsp._jspService(StoreIbesIdentification_jsp.java:68)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Another error occurs on *refreshing the same JSP page*
javax.servlet.ServletException: Could not initialize class com.forbes.finapps.util.HibernateUtil
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:843)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:776)
org.apache.jsp.jsp.test.StoreIbesIdentification_jsp._jspService(StoreIbesIdentification_jsp.java:110)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NoClassDefFoundError: Could not initialize class com.forbes.finapps.util.HibernateUtil
com.forbes.finapps.ibes.beans.identification.IbesIdentificationManager.createAndStoreIbesIdentification(IbesIdentificationManager.java:106)
com.forbes.finapps.ibes.beans.identification.IbesIdentificationManager.generateDummyIdentificationRecords(IbesIdentificationManager.java:92)
org.apache.jsp.jsp.test.StoreIbesIdentification_jsp._jspService(StoreIbesIdentification_jsp.java:68)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
*EDIT* ---- Now I'm seeing some useful errors in the log files :
java.lang.ExceptionInInitializerError
at com.forbes.finapps.util.HibernateUtil.<clinit>(HibernateUtil.java:22)
at com.forbes.finapps.ibes.beans.identification.IbesIdentificationManager.createAndStoreIbesIdentification(IbesIdentificationManager.java:106)
at com.forbes.finapps.ibes.beans.identification.IbesIdentificationManager.generateDummyIdentificationRecords(IbesIdentificationManager.java:92)
at org.apache.jsp.jsp.test.StoreIbesIdentification_jsp._jspService(StoreIbesIdentification_jsp.java:68)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/forbes/finapps/ibes/beans/identification/IbesIdentification.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
at com.forbes.finapps.util.HibernateUtil.<clinit>(HibernateUtil.java:18)
... 23 more
Caused by: org.hibernate.PropertyNotFoundException: field [id] not found on com.forbes.finapps.ibes.beans.identification.IbesIdentification
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:112)
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:104)
at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:127)
at org.hibernate.util.ReflectHelper.getter(ReflectHelper.java:83)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:71)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:401)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:334)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
at org.hibernate.cfg.Configuration.add(Configuration.java:669)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:504)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
... 30 more
Name and version of the database you are using:
MySQL 4.0
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
The logs didn't show any errors
Mar 1, 2007 11:37:25 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.2
Mar 1, 2007 11:37:25 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Mar 1, 2007 11:37:25 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Mar 1, 2007 11:37:25 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Mar 1, 2007 11:37:25 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Mar 1, 2007 11:37:25 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Mar 1, 2007 11:37:25 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : com/forbes/finapps/ibes/beans/identification/IbesIdentification.hbm.xml
Mar 1, 2007 11:37:25 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: com.forbes.finapps.ibes.beans.identification.IbesIdentification -> ibes_identification