-->
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.  [ 2 posts ] 
Author Message
 Post subject: Update sentence in a Spring application
PostPosted: Mon Feb 14, 2005 2:16 pm 
Newbie

Joined: Mon Feb 14, 2005 2:05 pm
Posts: 2
Location: Madrid
Hi all, i have the following method that belongs to a Spring application
Code:
    public void increasePrice(Product prod, int pct) {
        logger.info("Increasing price by " + pct + "%");
        SqlUpdate su = new SqlUpdate(ds, "update products set price = price * (100 + ?) / 100 where id = ?");
        su.declareParameter(new SqlParameter("increase", Types.INTEGER));
        su.declareParameter(new SqlParameter("ID", Types.INTEGER));
       
        su.compile();
       
        Object[] oa = new Object[2];
        oa[0] = new Integer(pct);
        oa[1] = new Integer(prod.getId());
       
        int count = su.update(oa);
        logger.info("Rows affected: " + count);
    }


The implementation is based in Spring JDBC, but i would like to change to HQL. How can i get this?
I am reading Hibernate API. HibernateTemplate contains utility methods to query against a database. I am trying with save(Object o) and saveOrUpdate(Object o) but it doesn't run.
Any help will be wellcome.
Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 8:34 pm 
Newbie

Joined: Mon Feb 14, 2005 2:05 pm
Posts: 2
Location: Madrid
I will find it:
Code:
    public void increasePrice(Product prod, int pct) {
        logger.info("Increasing price by with Hibernate " + pct + "%");
        prod.setPrice(new Double(prod.getPrice().doubleValue() * (100.0 + pct)/100));
        this.getHibernateTemplate().saveOrUpdate(prod);
    }


The mapping file is Product.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
   <class name="bus.Product" table="products">
      <id name="id" column="id" unsaved-value="0">
         <generator class="increment"/>
      </id>
      <property name="description" column="description"/>
      <property name="price" column="price"/>
   </class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.