-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: 1000...00 times to test hibernate in jsp,some question to me
PostPosted: Sat May 29, 2004 7:15 am 
Regular
Regular

Joined: Tue Dec 30, 2003 2:35 am
Posts: 85
here is my jsp code(code runs ok):
press.jsp
Code:
<%@ page contentType="text/html;charset=GBK" %>
<%@ page language="java" %>
<%@ page import="javax.naming.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="net.sf.hibernate.SessionFactory" %>
<%@ page import="net.sf.hibernate.Session" %>
<%@ page import="net.sf.hibernate.Transaction" %>
<%!
  javax.sql.DataSource ds;
  SessionFactory sf;
  Session objSession;
  Transaction tx;
%>

<%
  try {
      Context ctx = new InitialContext();
      ds = (javax.sql.DataSource)ctx.lookup("java:/OracleDS");
      Connection conn = ds.getConnection();
      Statement st = conn.createStatement();
      String sqlStr = "select * from rkxx where rownum<=100";
      ResultSet rs = st.executeQuery(sqlStr);
      while(rs.next()){
        out.println(rs.getString("PERSONID")+"<br>");
      }
      rs.close();
      st.close();
      conn.close();
      out.println("success to connect database<br>");
      out.println("start use the hibernate<br>");
      sf = (SessionFactory)ctx.lookup("java:/hibernate/HibernateFactory");
     
      for(long i=0;i<1000000000;i++)
      {
          objSession = sf.openSession();
          //if (!objSession.isConnected())
          //    objSession.reconnect();
          tx = objSession.beginTransaction();
          com.SFHC.RepairSFHC.DB.SFHCNO objNo = new com.SFHC.RepairSFHC.DB.SFHCNO();
          objNo.setv_JMZH("77777777");
          objSession.save(objNo);
          objSession.flush();
          if(tx!=null)
             tx.commit();
          objSession.close();
      }   
      out.println("succeed to mark a record!");
    } catch (Exception e) {
      if(tx!=null)
         tx.rollback();
      out.println("error!!!!!!!!!!!!!!" + e.toString());
    }
    finally
    {
       //objSession.close();
    }
%>


question1:
when i visit the press.jsp url,the oracle have data,but like the press code i wrote,1000000000 will spend too long,the jsp page does't appear,it tell the error info at a few hours later:can not find the page,but in the backgound,data is still inserted to the oracle.so strange,so strange!!!!!!!the page does't work,but the data is still inserted to the oracle??????

question2:
after 30 mintue,use the other JSP page to visit the oracle,it take 40 second,but if i use the JSP page at once again,the speed to visit the oracle is very fast!!!how did it happen?why when i use the JSP page after 30 minute first time,it seems so slowly,use the jsp page at once again,the speed is so faster!!!!!(i use mbean of the jboss,and as my viewpoint,whenever i use the jsp page to vivit the oracle,the speed should be very,very fast,not after 30 minute change to so slowly)

question3: how can i get some jboss info,for example how many subsequent user is use the jboss at the same time!!!

thank you for you help!


Top
 Profile  
 
 Post subject: also a terrible problem of the other test.jsp
PostPosted: Sat May 29, 2004 7:44 am 
Regular
Regular

Joined: Tue Dec 30, 2003 2:35 am
Posts: 85
also a terrible problem of the other test.jsp(i use the mbean of jboss)
test.jsp
Code:
<%@ page contentType="text/html;charset=GBK" %>
<%@ page language="java" %>
<%@ page import="javax.naming.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="net.sf.hibernate.SessionFactory" %>
<%@ page import="net.sf.hibernate.Session" %>
<%@ page import="net.sf.hibernate.Transaction" %>
<%!
  javax.sql.DataSource ds;
  SessionFactory sf;
  Session objSession;
  Transaction tx;
%>

<%
  try {
      Context ctx = new InitialContext();
      ds = (javax.sql.DataSource)ctx.lookup("java:/OracleDS");
      Connection conn = ds.getConnection();
      Statement st = conn.createStatement();
      String sqlStr = "select * from rkxx where rownum<=100";
      ResultSet rs = st.executeQuery(sqlStr);
      while(rs.next()){
        out.println(rs.getString("PERSONID")+"<br>");
      }
      rs.close();
      st.close();
      conn.close();
      out.println("success to connect database<br>");
      out.println("start use the hibernate<br>");
      sf = (SessionFactory)ctx.lookup("java:/hibernate/HibernateFactory");
      objSession = sf.openSession();
      //if (!objSession.isConnected())
      //    objSession.reconnect();
      tx = objSession.beginTransaction();
      com.SFHC.RepairSFHC.DB.SFHCNO objNo = new com.SFHC.RepairSFHC.DB.SFHCNO();
      objNo.setv_JMZH("11111111");
      objSession.save(objNo);
      objSession.flush();
      if(tx!=null)
         tx.commit();
      out.println("succeed to mark a record!");
    } catch (Exception e) {
      if(tx!=null)
         tx.rollback();
      out.println("error!!!!!!!!!!!!!!" + e.toString());
    }
    finally
    {
       objSession.close();
    }
%>


when i press the button of my computer-->F5(to refresh the test.jsp page),press the F5 30 second then the page tell me the fllowed error:
why? why? why?
error1:
Code:
org.apache.jasper.JasperException: Rollback failed with exception
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:220)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.jboss.web.tomcat.tc4.statistics.ContainerStatsValve.invoke(ContainerStatsValve.java:76)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:65)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:577)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:197)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677)
   at java.lang.Thread.run(Thread.java:534)


error2:
net.sf.hibernate.HibernateException: Session is closed

error3:
net.sf.hibernate.JDBCException: Could not save object

error4:
success to connect database
start use the hibernate
error!!!!!!!!!!!!!!net.sf.hibernate.JDBCException: Cannot open connection

error5:
some other error info!!!!

could you tell me why????

thank you for you help!


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 29, 2004 11:29 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
You are not using sessions and transactions properly with Hibernate. Look at http://www.hibernate.org/hib_docs/reference/en/html/manipulatingdata.html#manipulatingdata-endingsession-exceptions

There is no need to call flush in a Hibernate transaction.

Try this change and see how the behavior changes.


Sherman


Top
 Profile  
 
 Post subject: your advice can't work!
PostPosted: Sun May 30, 2004 8:09 am 
Regular
Regular

Joined: Tue Dec 30, 2003 2:35 am
Posts: 85
thank you for more help!!!

hi every one,you can also try it on your owner test platform,i guess you will also get the error info of mine!!!!!

is it serious or fatal to my system?????(is it a hint to the stability?????)
i'am afraid my stability of my system!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 30, 2004 8:39 am 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
Answers to your first post:

question 1: The JSP is working to insert 1,000,000,000 rows in a table. This is a bad test, because you would never do that sort of work in single JSP or servlet call - a background process should do it. That is going to take a long time, so the JSP does not come back in a reasonable time. The work still gets done though, so your data appears.

question 2: Hibernate caches results. 1st query is slow, later queries are faster. The cache clears itself out, based on time or LRU, so you go back to being slow the 1st time.

question 3: check on the JBoss forums for how to work out number of users.



Answer to your last post:

I have said before that your transaction management is wrong. Working with JBoss and the Hibernate Factory in JNDI, you only use:

Code:
UserTransaction ut = .... ;
Session sess = factory.openSession();
try {
    // do some work
    ...
    sess.flush();
}
catch (Exception e) {
    ut.setRollbackOnly();
    throw e;
}
finally {
    sess.close();
}


This is all in the documentation.


Sherman


Top
 Profile  
 
 Post subject: thank you very much!!!!
PostPosted: Sun May 30, 2004 11:19 am 
Regular
Regular

Joined: Tue Dec 30, 2003 2:35 am
Posts: 85
here is my jboss-service.xml
Code:
<server>
<mbean code="net.sf.hibernate.jmx.HibernateService"
    ......
    [color=red]<attribute name="UserTransactionName">UserTransaction</attribute>[/color]
</mbean>
</server>


i don't know how to use the UserTransactionName<-->UserTransaction marked in jboss-service.xml

i use the :
Code:
UserTransaction UserTx
UserTx = (UserTransaction)ctx.lookup("javax.transaction.UserTransaction");


but the code tell me the error,it not a jndi name

i don't know how to use UserTransaction (mbean of jboss),show me some code how to use initialize the variable-->UserTransaction(UserTx),use lookup("javax.transaction.UserTransaction") tell the error info.

otherwise you said the UserTransaction ,is the javax.transaction.UserTransaction


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 30, 2004 12:33 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
This is not well documented outside the Hibernate code itself. Here's how to get the UserTransaction.

Code:
net.sf.hibernate.transaction.JNDITransactionManagerLookup lookup = ( net.sf.hibernate.transaction.JNDITransactionManagerLookup) new net.sf.hibernate.transaction.JBossTransactionManagerLookup;

String userTransactionName = lookup.getUserTransactionName();



You should just lookup JNDI with the userTransactionName .

I also use:

Code:

javax.transaction.TransactionManager transactionMgr = lookup.getTransactionManager(new Properties());

// and

javax.transaction.Transaction transaction = transactionMgr.getTransaction();



With either of these, you can rollback, setRollbackOnly and commit.


Sherman


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.