Hello -

I have 3 pojos Arch, Feature and Comment.  I have one-to-many relationships
between Arch and Comment and Feature and Comment.

Here is the xdoclet code from Arch (identical to setup in Feature) :

   /**
    * @hibernate.bag cascade="all" lazy="false" order-by="date"
    * @hibernate.collection-key column="competition"
    * @hibernate.collection-one-to-many class="org.dba.model.Comment"
    * @struts.form-field
    */
   public List getComments()
   {
     return comments;
   }


Here is the xdoclet code from Comment:


   /**
    * Returns a reference to the pojo it belongs to
    * @hibernate.many-to-one column="competition"
    *                        class="org.dba.model.Arch"
    *                        cascade="none"
    */
   public Arch getCompetition() {
       return competition;
   }
   public void setCompetition(Arch competition) {
       this.competition = competition;
   }



User's may add comments via a form from a public page.  This form calls a
method in ArchAction called addCommentPublic.  See below:


public ActionForward addCommentPublic(ActionMapping mapping, ActionForm
form,
           HttpServletRequest request, HttpServletResponse response)
           throws Exception {

       ArchForm archForm = (ArchForm)form;
       ArchManager mgr = (ArchManager) getBean("archManager");
       Arch arch = mgr.getArch(archForm.getId());

       Date valueDate = new Date();
       String valueCopy = request.getParameter("newCommentCopy");
       String valueUser = "anonymous";

       Comment comment = new Comment();
       comment.setDate(valueDate);
       comment.setCopy(valueCopy);
       comment.setUser(valueUser);
       arch.getComments().add(comment);

       mgr.saveArch(arch);
       ArchForm archFormNew = (ArchForm) convert(arch);
       updateFormBean(mapping, request, archFormNew);
       StartupListener.reloadComments(getServlet().getServletContext());
       return mapping.findForward("view");

   }



I also have on the homepage a list of the 10 most recent comments
submited..which should link to their respective parent ie.  some should link
to a arch detail view and some should link to a feature detail view.

I have a method in LookupDAOHibernate called getComments() which is called
from the startup listener.  it is also called when a user adds a comment.
The comments are sorted in descending order.... In LookupManagerImpl I'm
returning a list of wrapper objects that mirror the comment objects.  I did
this so that I could store the id's numbers of the parent objects....and
make them accessible from my jsp pages.   below are the lookup functions.

LookupDAOHibernate:
   public List getComments() {
       if (log.isDebugEnabled()) {
           log.debug("retrieving all last 5 Comments...");
       }

       DetachedCriteria criteria = DetachedCriteria.forClass(Comment.class
);
       criteria.addOrder(Order.desc("date"));
       int offset = 0;
       int count = 5;
       return getHibernateTemplate().findByCriteria(criteria, offset,
count);


   }

LookupManagerImpl:

       public List getAllComments() {


       //return dao.getComments();


       List    comments     = dao.getComments();
       List   toReturn = new ArrayList();
       for (Iterator iter = comments.iterator(); iter.hasNext();)
         {
         Comment       comment       = (Comment) iter.next();
         CommentDetail commentDetail = new CommentDetail(comment);
         toReturn.add(commentDetail);
         }
       return toReturn;


   }


When a new comment is added, a reload function is called in the
startupListener which triggers the getComments() method in LookupManagerImpl
and LookupDAOHibernate....refreshing the last 10 comments list....

my problem is that the very first comment in the list (which is really the
last comment added) does not have a reference to the id number of it's
parent....although the id number is present in the database..  If i save the
parent object through the web-based form...the context is reloaded and the
id number appears.  Any tips would be greatly appreciated.


This application is based on 1.8.2
Using default setup - struts, mysql
Working on Windows
Using Tomcat 5



Best,
Dorothy

Reply via email to