Within an Appfuse project is there an easy way to get a hibernate
session and execute an HQL query and update?

Sorry if this is an obvious spring beginner question, still trying to
figure out everything going on here.

I'm doing this in my onSubmit method of one of my form controlers to
inject some data into a newly created object.

I was thinking of doing this in the formBackingObject but the else
block where the new object is created gets called twice (not sure
why).

Thanks,

Luke

protected Object formBackingObject(HttpServletRequest request)
   throws Exception {
       String patientId = request.getParameter("patientId");
       Patient patient = null;

       if (!StringUtils.isEmpty(patientId)) {
           patient = patientManager.getPatient(patientId);
       } else {
//this gets called twice
           patient = new Patient();
       }

       return patient;
   }


On 3/6/07, Luke Shannon <[EMAIL PROTECTED]> wrote:
Hi Matt;

I may be able to achieve my goal by calling a stored procedure using
hibernate. The last part of chapter 7 of your book has me thinking
this will work.

I am going to give this a try tomorrow.

Luke

On 3/6/07, Luke Shannon <[EMAIL PROTECTED]> wrote:
> Ah, I know the feeling. Thanks for getting back to me though :-)
>
> I am reading your chapter in Spring Live on Hibernate (Chapter 7). I'm
> hoping to figure out a better way to do this from that.
>
> BTW: This is a great book!
>
> Luke
>
> On 3/6/07, Matt Raible <[EMAIL PROTECTED]> wrote:
> > Nope, I'm just swamped with work right now and couldn't think of an
> > easy answer. ;-)
> >
> > Matt
> >
> > On 3/6/07, Luke Shannon <[EMAIL PROTECTED]> wrote:
> > > Hi Matt;
> > >
> > > Am I totally missing the point with the code I sent?
> > >
> > > Thanks,
> > >
> > > Luke
> > >
> > > On 3/5/07, Luke Shannon <[EMAIL PROTECTED]> wrote:
> > > > BTW:
> > > >
> > > > PatientData is an inner class of the PatientFormController  class
> > > > (just in case it wasn't clear).
> > > >
> > > > On 3/5/07, Luke Shannon <[EMAIL PROTECTED]> wrote:
> > > > > Hi Matt;
> > > > >
> > > > > Actually I am going to do something like below. The data I'm getting
> > > > > this from is a seperate DB table than the ones I have generated using
> > > > > appfuse (I have created my own ETL process to build it). Is this the
> > > > > hard way to do it? I am still learning hibernate and spring so I am
> > > > > not totally comfortable with the framework.
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Luke
> > > > >
> > > > > public ModelAndView onSubmit(HttpServletRequest request,
> > > > >                                  HttpServletResponse response, Object 
command,
> > > > >                                  BindException errors)
> > > > >     throws Exception {
> > > > >         if (log.isDebugEnabled()) {
> > > > >             log.debug("entering 'onSubmit' method...");
> > > > >         }
> > > > >
> > > > >         Patient patient = (Patient) command;
> > > > >         boolean isNew = (patient.getPatientId() == null);
> > > > >         Locale locale = request.getLocale();
> > > > >
> > > > >         if (request.getParameter("delete") != null) {
> > > > >             
patientManager.removePatient(patient.getPatientId().toString());
> > > > >
> > > > >             saveMessage(request, getText("patient.deleted", locale));
> > > > >         } else {
> > > > >         String countryId = request.getParameter("countryId");
> > > > >             String doctorId  = request.getParameter("doctorId");
> > > > >             PatientData p_data = new PatientData(countryId);
> > > > >                 patient.setPatientTag(p_data.getTag());
> > > > >             patient.setTreatmentarm(p_data.getTreatmentArm());
> > > > >             patient.setDoctorId(new Long(doctorId));//this is going to
> > > > > come from the request
> > > > >             patientManager.savePatient(patient);
> > > > >
> > > > >             String key = (isNew) ? "patient.added" : 
"patient.updated";
> > > > >             saveMessage(request, getText(key, locale));
> > > > >
> > > > >             if (!isNew) {
> > > > >                 return new ModelAndView("redirect:editPatient.html",
> > > > > "patientId", patient.getPatientId());
> > > > >             }
> > > > >         }
> > > > >
> > > > >         return new ModelAndView(getSuccessView());
> > > > >     }
> > > > >     public class PatientData {
> > > > >         private String tag;
> > > > >         private int treatmentArm;
> > > > >         PatientData(String countryId) {
> > > > >                 //connect to the DB to get the next available values 
for the countryId
> > > > >                 this.tag = "value from DB";
> > > > >                 this.treatmentArm = 0;//value from the DB
> > > > >                 //update the assignment date so these values will not 
be selected again
> > > > >         }
> > > > >                 /**
> > > > >                  * @return the tag
> > > > >                  */
> > > > >                 public String getTag() {
> > > > >                         return tag;
> > > > >                 }
> > > > >                 /**
> > > > >                  * @param tag the tag to set
> > > > >                  */
> > > > >                 public void setTag(String tag) {
> > > > >                         this.tag = tag;
> > > > >                 }
> > > > >                 /**
> > > > >                  * @return the treatmentArm
> > > > >                  */
> > > > >                 public int getTreatmentArm() {
> > > > >                         return treatmentArm;
> > > > >                 }
> > > > >                 /**
> > > > >                  * @param treatmentArm the treatmentArm to set
> > > > >                  */
> > > > >                 public void setTreatmentArm(int treatmentArm) {
> > > > >                         this.treatmentArm = treatmentArm;
> > > > >                 }
> > > > >
> > > > >     }
> > > > >
> > > > >
> > > > >
> > > > > On 3/5/07, Matt Raible <[EMAIL PROTECTED]> wrote:
> > > > > > The method of how data is retrieved from the database should already
> > > > > > be setup for you - with Managers, DAOs, etc.  Showing us pseudo code
> > > > > > for what you're trying to do with make it much easier to help.
> > > > > >
> > > > > > Matt
> > > > > >
> > > > > > On 3/5/07, Luke Shannon <[EMAIL PROTECTED]> wrote:
> > > > > > > Thanks Mat, formBackingObject() seems to be the way to go. Do you 
see
> > > > > > > any problem using the Jakarta-Commons DB connection pool to 
obtain the
> > > > > > > data from the DB? Or is there a better approach to this?
> > > > > > >
> > > > > > > On 3/4/07, Matt Raible <[EMAIL PROTECTED]> wrote:
> > > > > > > > You could do this in your DAO where you originally fetch 
everything.  Also,
> > > > > > > > there's logic in your FormController's formBackingObject() that 
gets your
> > > > > > > > object from the database before populating it from request 
parameters. This
> > > > > > > > means you don't have to store these fields in hidden fields.  
If this
> > > > > > > > doesn't work, you might try storing the non-editable fields in 
hidden fields
> > > > > > > > or read-only fields.
> > > > > > > >
> > > > > > > > Matt
> > > > > > > >
> > > > > > > >
> > > > > > > > On 3/4/07, Luke Shannon <[EMAIL PROTECTED]> wrote:
> > > > > > > > >
> > > > > > > > > Hi;
> > > > > > > > >
> > > > > > > > > This may be a more of a Spring question, although I am hoping 
there is
> > > > > > > > > something within the Appfuse tools to assist with this.
> > > > > > > > >
> > > > > > > > > I have a Pojo I have created in my application and I have 
used Appgen
> > > > > > > > > to create everything I need for the CRUD operations.
> > > > > > > > >
> > > > > > > > > What I would like to do now is modify the application so 
specific
> > > > > > > > > fields in the Pojo are set using data from a DB and not from 
user
> > > > > > > > > input from the web tier.
> > > > > > > > >
> > > > > > > > > Working within the Struts framework (Appfuse 1.9.4) where is 
the best
> > > > > > > > > place to implement such a change? Is there a best practise for
> > > > > > > > > something like this?
> > > > > > > > >
> > > > > > > > > Thanks,
> > > > > > > > >
> > > > > > > > > Luke
> > > > > > > > >
> > > > > > > > >
> > > > > > > > 
---------------------------------------------------------------------
> > > > > > > > > To unsubscribe, e-mail:
> > > > > > > > [EMAIL PROTECTED]
> > > > > > > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > http://raibledesigns.com
> > > > > > >
> > > > > > > 
---------------------------------------------------------------------
> > > > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > http://raibledesigns.com
> > > > > >
> > > > > > 
---------------------------------------------------------------------
> > > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> >
> > --
> > http://raibledesigns.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to