How would you implement your way for updating tables?
--- "Gentry, Michael (Contractor)" <michael_gentr..anniemae.com> wrote:
> I've never used UpdateQuery before, but try:
>
> UpdateQuery updated =
> new UpdateQuery(Customer.class,
> template.expWithParameters(params));
>
> Also, I don't think you need the commitChanges() at the end ... That
> would be more useful if you were working with actual CayenneDataObjects,
> which you aren't. Also, I think your object graph might get out-of-sync
> this way, which could lead to more problems.
>
> /dev/mrg
>
>
> -----Original Message-----
> From: Alan Baltazar [mailto:acatalan..ahoo.com]
> Sent: Wednesday, April 05, 2006 5:13 PM
> To: cayenne-use..ncubator.apache.org
> Subject: UpdateQuery not updating
>
>
> 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
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
This archive was generated by hypermail 2.0.0 : Wed Apr 05 2006 - 18:57:21 EDT