-->
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.  [ 12 posts ] 
Author Message
 Post subject: retrive a nested Collection in a jsp
PostPosted: Thu Jul 28, 2005 2:05 pm 
Beginner
Beginner

Joined: Tue Jun 28, 2005 8:51 pm
Posts: 20
Location: Bergamo, Italy
In an Hibernate session i load an ITEM object wich have as property :
String a;
Collection b;

and collection b has String c as property.

Then in the jsp page (using JSTL) i can use normally ITEM.a to show the variable,
but how can i show the nested collection variable? (ITEM.b.c gives ERROR!)

tnkx a lot ;)

ps: using hib 2


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 2:07 pm 
Beginner
Beginner

Joined: Tue Jun 28, 2005 8:51 pm
Posts: 20
Location: Bergamo, Italy
ERRATA CORRIGE:
the question starts:

In an Hibernate session i use a createQuery to retrive a list of ITEM object wich have as property : ...


Top
 Profile  
 
 Post subject: Re: retrive a nested Collection in a jsp
PostPosted: Thu Jul 28, 2005 2:20 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
vanholy wrote:
(ITEM.b.c gives ERROR!)


What's the error?

Are you closing your Hibernate session before the JSP gets a chance to execute?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 2:22 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Post your error as well as your mappings.

I still wonder why people keep ignoring filling out the initial information (Hibernate version, mappings, code...).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 2:26 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
sven wrote:
Post your error as well as your mappings.

I still wonder why people keep ignoring filling out the initial information (Hibernate version, mappings, code...).


Frustrating isn't it? If I'm waiting for a recompile or my server to start up, I can answer a question in the meantime. When I open a thread that provides no info, it just wastes my time (and everyone else's).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 2:31 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Welcome to the Hibernate forum :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 2:38 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
christian wrote:
Welcome to the Hibernate forum :)


I already thought about modifying the forum again creating drop down menus for information like Hibernate version and database version (both including a value "irrelevant") and maybe also textareas for more information (stack trace etc.)...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 3:09 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Hopeless...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 3:47 pm 
Beginner
Beginner

Joined: Tue Jun 28, 2005 8:51 pm
Posts: 20
Location: Bergamo, Italy
sven wrote:
Post your error as well as your mappings.

I still wonder why people keep ignoring filling out the initial information (Hibernate version, mappings, code...).


I use a servlet filter that keep session under a struts application.

The problem i think is about the use of JSTL to retrive data. Now i try with a nested logic tag, i' ll explain better the problem if i have more problems ;)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 6:28 pm 
Beginner
Beginner

Joined: Tue Jun 28, 2005 8:51 pm
Posts: 20
Location: Bergamo, Italy
Sorry for no much info of initial post entry but i was late and have no time to write it all. Now try to explain better:

I use a servlet filter under struts.

In a Hibernate session i use a createQuery to retrive a List of ITEM object :
public Collection getMetaObjects(){

List result = null;
Transaction tx = null;

try {

tx =getSession().beginTransaction();
Query q = getSession().createQuery("from MetaObject");
result = q.list();
tx.commit();
}
catch (HibernateException e) {
System.out.println("Error!!!");
e.printStackTrace();
if (tx != null) Persistence.rollback(tx);
}

return result;
}


Then return the list to my action, i bind it to request scope:

MetaObjectDAO metaObjectDAO = new MetaObjectDAO();
List metaObjects = (List) metaObjectDAO.getMetaObjects();
request.setAttribute("metaObjects",metaObjects);

if (metaObjects == null ) {
//saveErrors(request, errors);
return (mapping.findForward("failure"));
}

return (mapping.findForward("successMetaObjects"));


At the end i want to display the List using Struts Taglib or JSTL taglibs.

No problem for displayng a table with Lists content that is MetaObject.

<table border="1" bordercolor="ffffff">
<tr>
<th><B>name </B></th>
<th><B>from</B></th>
<th><B>where</B></th>
</tr>

<c:forEach var="MetaObject" items="${metaObjects}" varStatus="loop">

<c:set var="tdclass" value="oddRow"/>
<c:if test="${loop.count % 2 == 0}">
<c:set var="tdclass" value="evenRow"/>
</c:if>

<tr>

<td class='<c:out value="${tdclass}"/>'>
<c:out value="${MetaObject.name}"/>
</td>

<td class='<c:out value="${tdclass}"/>'>
<c:out value=" ${MetaObject.from}"/>
</td>

<td class='<c:out value="${tdclass}"/>'>
<c:out value=" ${MetaObject.where}"/>
</td>

</tr>

</c:forEach>

</table>



MY PROBLEM is that i am not able to render the set (correctly mapped with bidirectional association ) nested in MetaObject:


public class MetaObject implements Serializable {

private Long id;
private String where;
private Set attributes;
....
}

Can you helpMe??? (i think i was exaustive this time ;)

G
bye


Ps:I do not write else info because no hibernate error given..

[b]Hibernate version:2.1

[b]Name and version of the database you are using MySql4


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 7:54 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Quote:
I do not write else info because no hibernate error given..


I could be rude and ask why you ask for help in the Hibernate forum, if there is no Hibernate error, but I won't do that. :)

It's really hard to tell, what your problem might be. Without any error information, mappings and code which shows where your problem is (I don't see where you try to access the Set of attributes in MetaObject) it could be nearly anything what could be wrong.

Maybe your Hibernate session might have been closed when you try to access the Set. But in such a case you will see a Hibernate exception.

Or is it even a Struts or JSTL problem?

Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 8:14 pm 
Beginner
Beginner

Joined: Tue Jun 28, 2005 8:51 pm
Posts: 20
Location: Bergamo, Italy
Thank again for reply. Finally i solved the problem and it was an error using properties fields on the way of calling the collection from the jsp. MEA CULPA :)

bye


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