-->
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.  [ 1 post ] 
Author Message
 Post subject: Get column names from session.createQuery
PostPosted: Sat Mar 29, 2008 5:00 pm 
Beginner
Beginner

Joined: Sat Dec 01, 2007 4:34 pm
Posts: 20
In my app I have a database that contains a table Log that logs logtime for a user. It contains the following columns:logID, username, logTime.

On this table I'm running several similar select statements. These selections are at the end displayed in a jsp file. In most cases only two columns are needed to display the selections from the table. These could for instance be: username and number of times logged in, and username and last time logged in. I've shown an example below.

The problem is that the only thing that changes in the jsp file is the column names. Now I use a different jsp file for each select statement. But this seems a bit wrong. Is there a way to get the column names from the rows selected?


Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();

   
List logs = session.createQuery("SELECT new map( l.username as username, count(*) as count ) from Log as l where l.username=:u GROUP BY l.username").setString("u", username).list();
    session.getTransaction().commit();




jsp-file

Code:
<table>
<tr>
<th>Username</th><th>Count</th>
</tr>

<c:forEach items="${model.logList}" var="log" varStatus="rowCounter">
                   
     <c:choose>
        <tr>             
           <td><c:out value="${log.username}"/></td>
           <td><c:out value="${log.count}"/></td>
        </tr>
</c:forEach>
</table>


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

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.