cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan Baltazar <acatal...@yahoo.com>
Subject UpdateQuery not updating
Date Wed, 05 Apr 2006 21:12:35 GMT
Hello,

  I'm trying to update a field in a table using the UpdateQuery. The following code
doesn't update my data.

Date dob = null;
DateFormat df = DateFormat.getDateInstance();
DataContext ctxt = BasicServletConfiguration.getDefaultContext(request.getSession());

String customerName = request.getParameter("customerName");
String dateOfBirth = request.getParameter("dateOfBirth");
        
Expression template = Expression.fromString("customerName = $customerName");
Map params = new HashMap();
params.put("customerName", customerName);

UpdateQuery updated = new UpdateQuery(Customer.class,template);    
    
try { 
   dob = df.parse(dateOfBirth);        	
}
catch(ParseException e) {
   System.out.println("Unable to parse ");
}
        
updated.addUpdAttribute("DATE_OF_BIRTH",dob);
ctxt.performNonSelectingQuery(updated);
ctxt.commitChanges(); 	

return mapping.findForward("success");
}

this is the mysql table,
CREATE TABLE `CUSTOMER` (
  `CUSTOMER_ID` int(10) unsigned NOT NULL ,
  `CUSTOMER_NAME` varchar(20) NOT NULL default '',
  `DATE_OF_BIRTH` date NOT NULL default '0000-00-00',
  PRIMARY KEY  (`CUSTOMER_ID`)
) TYPE=InnoDB;

here's the data object,
public class _Customer extends org.objectstyle.cayenne.CayenneDataObject {

    public static final String CUSTOMER_NAME_PROPERTY = "customerName";
    public static final String DATE_OF_BIRTH_PROPERTY = "dateOfBirth";
    public static final String PRODUCT_ARRAY_PROPERTY = "productArray";

    public static final String CUSTOMER_ID_PK_COLUMN = "CUSTOMER_ID";

    public void setCustomerName(String customerName) {
        writeProperty("customerName", customerName);
    }
    public String getCustomerName() {
        return (String)readProperty("customerName");
    }
    
    
    public void setDateOfBirth(java.util.Date dateOfBirth) {
        writeProperty("dateOfBirth", dateOfBirth);
    }
    public java.util.Date getDateOfBirth() {
        return (java.util.Date)readProperty("dateOfBirth");
    }
    
    
    public void addToProductArray(dao.Product obj) {
        addToManyTarget("productArray", obj, true);
    }
    public void removeFromProductArray(dao.Product obj) {
        removeToManyTarget("productArray", obj, true);
    }
    public List getProductArray() {
        return (List)readProperty("productArray");
    }
    
    
}


  if there's any other shorter way to do this with UpdateQuery, I'm listening

thanks for any help,
alan

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Mime
View raw message