-->
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: Using Struts with Hibernate Efficiently
PostPosted: Mon Aug 02, 2004 3:51 am 
Newbie

Joined: Sun Aug 01, 2004 6:52 am
Posts: 1
In my application I am using struts and hibernate together to edit the contents of a database. To load data from the database I am doing something like this in the action execute method:



Code:
DbObject dbobject = (DbObject)session.load(DbObject.class, new Long(idObj));
org.apache.struts.validator.DynaValidatorActionForm myform = (org.apache.struts.validator.DynaValidatorActionForm) form;
org.apache.commons.beanutils.PropertyUtils.copyProperties(myform, dbobject);               
session.close();


and to save information from the form back to the database, I am doing something like this in action execute method:

Code:
org.apache.struts.validator.DynaValidatorActionForm myform = (org.apache.struts.validator.DynaValidatorActionForm) form;
DbObject dbobject = (DbObject).load(DbObject.class, (Serializable) myform.get("idObj"));
org.apache.commons.beanutils.PropertyUtils.copyProperties(dbobject,myform);
session.save(dbobject);
session.flush();
session.connection().commit();
session.close();
                       

(Validation of data is being done using the validation capabilities of struts)

This works nicely where the textual and numeric data where the data is all in one table. It can work fairly well when there is a simple lookup to information in another table, single properties can be set manually. However I would like to know how to make this work efficiently for many to many type data. This is the case where in the main hibernate object (in the above examples dbobject) there is a property which is a java.util.Set which is a set of the 'selected' objects from a third table. In the Struts form, I would want this kind of information to appear as a multiple select list box, or an array of check boxes. What is the best way of projecting this information onto a struts form object from the hibernate object for editing, and visa versa for storing.


Thanks in advance for your suggestions!


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.