I am trying to insert message in databse through Hibernate. Message rate is 6000 message / minute. In first few seconds it is failing and giving following exception. After it is adding smoothly. why it is failing for first few seconds?
[b]Hibernate version:3.1
[b]Mapping documents:
<hibernate-mapping>
<class name="com.genuitec.hibernate.TrapTest" table="trap_test" schema="public">
<id name="id" type="java.lang.Long">
<column name="id" precision="22" scale="0" />
<generator class="increment"></generator>
</id>
<property name="message" type="java.lang.String">
<column name="message" length="4000" />
</property>
</class>
</hibernate-mapping>
[b]Code between sessionFactory.openSession() and session.close():
Session session = getSession();
Transaction tx = session.beginTransaction();
session.save(transientInstance);
tx.commit();
[b]Full stack trace of any exception that occurs:
SEVERE: Servlet.service() for servlet MessageReceiver threw exception
java.lang.NullPointerException
at com.genuitec.hibernate.TrapTestDAO.save(TrapTestDAO.java:26)
at MessageReceiver.doPost(MessageReceiver.java:96)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:212)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Thread.java:595)
org.hibernate.MappingException: Could not read mappings from resource: com/genuitec/hibernate/TrapTest.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:485)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
at com.genuitec.hibernate.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:59)
at com.genuitec.hibernate.HibernateSessionFactory.getSession(HibernateSessionFactory.java:43)
at com.genuitec.hibernate.BaseHibernateDAO.getSession(BaseHibernateDAO.java:13)
at com.genuitec.hibernate.TrapTestDAO.save(TrapTestDAO.java:25)
at MessageReceiver.doPost(MessageReceiver.java:96)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:212)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Thread.java:595)
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.genuitec.hibernate.TrapTest
at org.hibernate.cfg.Mappings.addClass(Mappings.java:118)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:154)
at org.hibernate.cfg.Configuration.add(Configuration.java:386)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)
[b]Name and version of the database you are using:postgre 8.2
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html