-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to process result set?
PostPosted: Thu Sep 29, 2005 5:22 pm 
Beginner
Beginner

Joined: Mon Sep 19, 2005 3:59 pm
Posts: 31
Hi there,

I just moved to Hibernate 3.0 & Struts 1.2, and wondering how to deal with the resultset.

e.g.

Code:
   public Systemuser[] getAllSystemusers() {

      /* will hold the systemusers we are going to return later */

      List systemusers = new ArrayList();

      /* a Hibernate session */

      Session session = null;

      /* we always need a transaction */

      Transaction tx = null;

      try {

         /* get session of the current thread */

         session = HibernateSessionFactory.currentSession();

         tx = session.beginTransaction();
         Query query = session
               .createQuery("from Systemuser order by userid");
         for (Iterator iter = query.iterate(); iter.hasNext();) {
            systemusers.add((Systemuser) iter.next());
         }
         tx.commit();
      } catch (HibernateException e) {
         e.printStackTrace();

         // it is recommended to roll back the transaction after an error
         // occured

         if (tx != null)
            try {
               tx.rollback();
            } catch (HibernateException e1) {
               e1.printStackTrace();
            }
      } finally {
         try {
            if (session != null)
               session.close();
         } catch (HibernateException e1) {
            e1.printStackTrace();
         }
      }
      return (Systemuser[]) systemusers.toArray(new Systemuser[0]);
   }



in Jsp,


Code:
<%@ page language="java" pageEncoding="UTF-8"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%> <html> <head> <title>JSP for systemuserListForm form</title> </head> <body> <table border="1"> <tbody>
<%-- set the header --%>
<logic:present name="systemuserListForm" property="systemusers">

<tr>
<td>Userid</td>
<td>Active</td>
<td>Role</td>
<td>Username</td>
<td>Password</td>
<td>Name</td>
<td>Personalid</td>
<td>Regdate</td>
<td>Business</td>
<td>Contact</td>
<td>Phone</td>
<td>Cellphone</td>
<td>Fax</td>
<td>Email</td>
<td>Web</td>
<td>Unit</td>
<td>Address</td>
<td>City</td>
<td>Province</td>
<td>Zip</td>
<td>Country</td>
<td>Logopath</td>
<td>Usersessiontime</td>
<td>Usersessionpage</td>
<td>Userlastvisit</td>
</tr>
<%-- start with an iterate over the collection systemuser --%> <logic:iterate name="systemuserListForm" property="systemusers" id="systemuser"> <tr>

<%-- systemuser information --%>
<td><bean:write name="systemuser" property="userid" /></td>
<%--
<td><html:checkbox disabled="true"  name="systemuser"  property="active"/></td>
--%>
<td><bean:write name="systemuser" property="role" /></td>

<td><bean:write name="systemuser" property="username" /></td>

<td><bean:write name="systemuser" property="password" /></td>

<td><bean:write name="systemuser" property="name" /></td>

<td><bean:write name="systemuser" property="personalid" /></td>

<td><bean:write name="systemuser" property="regdate" /></td>

<td><html:checkbox disabled="true"  name="systemuser"  property="business"/></td>

<td><bean:write name="systemuser" property="contact" /></td>

<td><bean:write name="systemuser" property="phone" /></td>

<td><bean:write name="systemuser" property="cellphone" /></td>

<td><bean:write name="systemuser" property="fax" /></td>

<td><bean:write name="systemuser" property="email" /></td>

<td><bean:write name="systemuser" property="web" /></td>

<td><bean:write name="systemuser" property="unit" /></td>

<td><bean:write name="systemuser" property="address" /></td>

<td><bean:write name="systemuser" property="city" /></td>

<td><bean:write name="systemuser" property="province" /></td>

<td><bean:write name="systemuser" property="zip" /></td>

<td><bean:write name="systemuser" property="country" /></td>

<td><bean:write name="systemuser" property="logopath" /></td>

<td><bean:write name="systemuser" property="usersessiontime" /></td>

<td><bean:write name="systemuser" property="usersessionpage" /></td>

<td><bean:write name="systemuser" property="userlastvisit" /></td>


<%-- edit and delete link for each systemuser --%> <td><html:link action="systemuserEdit.do?do=editSystemuser"
paramName="systemuser"
paramProperty="id"
paramId="id">Edit</html:link>
</td>
<td><html:link action="systemuserEdit.do?do=deleteSystemuser"
paramName="systemuser"
paramProperty="userid"
paramId="userid">Delete</html:link>
</td>
</tr>
</logic:iterate>
<%-- end interate --%>
</logic:present>
<%-- if systemusers cannot be found display a text --%> <logic:notPresent name="systemuserListForm" property="systemusers"> <tr> <td colspan="5">No systemuser found.</td> </tr> </logic:notPresent>

</tbody>
</table>

<br>
<%-- add and back to menu button --%>
<html:button property="add"
onclick="location.href='systemuserEdit.do?do=addSystemuser'">Add a new systemuser </html:button> &nbsp; <html:button property="back"
onclick="location.href='default.do'">Back to menu </html:button> </body> </html>




*****************************************

the stake trace

javax.servlet.ServletException: Exception thrown by getter for property role of bean systemuser
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.jsp.systemuserList_jsp._jspService(systemuserList_jsp.java:313)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063)
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

javax.servlet.jsp.JspException: Exception thrown by getter for property role of bean systemuser
org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:968)
org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:225)
org.apache.jsp.jsp.systemuserList_jsp._jspx_meth_bean_write_1(systemuserList_jsp.java:347)
org.apache.jsp.jsp.systemuserList_jsp._jspService(systemuserList_jsp.java:138)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063)
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)



Thanks for any ideas,

Lamborghini[/code]


Top
 Profile  
 
 Post subject: cause
PostPosted: Thu Sep 29, 2005 6:55 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
The root cause is should be burried somewhere in log files...I suggest you to dig for it.

First candidate for cause would be: 'lazy' attribute. Is there by any chance property role is an object mapped with lazy='true'?

Please post mapping too..

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: Re: cause
PostPosted: Thu Sep 29, 2005 7:07 pm 
Beginner
Beginner

Joined: Thu Dec 09, 2004 7:04 pm
Posts: 26
Location: Denver, CO
kgignatyev wrote:
First candidate for cause would be: 'lazy' attribute. Is there by any chance property role is an object mapped with lazy='true'?


And if it is, you should look at using managed JTA sessions. They stay open until the server is finished and so your JSP can still load lazy attributes.


Top
 Profile  
 
 Post subject: Re: cause
PostPosted: Thu Sep 29, 2005 7:07 pm 
Beginner
Beginner

Joined: Thu Dec 09, 2004 7:04 pm
Posts: 26
Location: Denver, CO
kgignatyev wrote:
First candidate for cause would be: 'lazy' attribute. Is there by any chance property role is an object mapped with lazy='true'?


And if it is, you should look at using managed JTA sessions. They stay open until the server is finished and so your JSP can still load lazy attributes.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.