彭老师,请教一个奇怪的问题-getHibernateTemplate().update(object);失效

08-05-19 82636

现在我正在做一个项目,使用struts2+spring2+hibernate3.2 ,在使用spring 的getHibernateTemplate().update(object);时出现问题,debug跟踪在一个action中,可以得到一个对象的属性的所有值,但是却无法进行更新操作。在控制台也没有其他错误输出,我在DAO实现中getHibernateTemplate().update(object);或saveOrUpdate();时,前后加了输出语句,都可以打印出来,但是update或saveOrUpdate却不执行。

另外一个action中,进行类似操作想更新,但是无法直接运行update。是先保存,后删除,只能变相实现更新。请问如何解决这个问题呢。多谢。

3
82636
2008-05-19 10:36

第一action的代码:

public String findProducts()throws Exception{
		Map condition = new HashMap();
		condition.put("start", 0);
		condition.put("limit", 5);
		if(name!=null){
			condition.put("name", name);
		}
		if(keywords!=null){
			condition.put("keywords", keywords);
		}
		if(fordistributor_begin!=null){
			condition.put("fordistributor_begin", fordistributor_begin);
			condition.put("fordistributor_end", fordistributor_end);
		}
		if(price_begin!=null){
			condition.put("price_begin", price_begin);
			condition.put("price_end", price_end);
		}
		if(categorycode!=null){
			condition.put("categorycode", categorycode);
		}
		products = productServiceTarget.advancedFind(condition);
		
		searchRule = condition.toString();
		System.out.println("searchRule======================="+searchRule);
		
		String productsetid = productSet.getProductsetid();
		productSet = productSetServiceTarget.findById(productsetid);
		productSet.setSearchRule(searchRule);
		System.out.println("p searchRule=++++++++++++++++++++++++++++++++++++++"+productSet.getSearchRule());
		System.out.println("############productSetServiceTarget####################"+productSetServiceTarget);
		productSetServiceTarget.saveOrUpdate(productSet);
		System.out.println("--------------------action--end-------------------------");
		
		return Common.STRUTS_SUCCESS;

控制台输出的内容:

Hibernate: select this_.productid as productid3_1_, this_.name as name3_1_, this_.price as price3_1_, this_.allcommission as allcommi4_3_1_, this_.fordistributor as fordistr5_3_1_, this_.forrun as forrun3_1_, this_.forpay as forpay3_1_, this_.keywords as keywords3_1_, this_.updatetime as updatetime3_1_, this_.registertime as registe10_3_1_, this_.categorycode as categor11_3_1_, this_.categoryid as categoryid3_1_, this_.mycategoryid as mycateg13_3_1_, this_.categoryname as categor14_3_1_, this_.supplierid as supplierid3_1_, this_.realprice as realprice3_1_, this_.propertyvalue as propert17_3_1_, this_.delivery as delivery3_1_, this_.description as descrip19_3_1_, this_.location as location3_1_, this_.number as number3_1_, this_.photopaths as photopaths3_1_, this_.photoid as photoid3_1_, photo2_.photoid as photoid18_0_, photo2_.bizcode as bizcode18_0_, photo2_.path as path18_0_ from product this_ left outer join photo photo2_ on this_.photoid=photo2_.photoid where this_.price between ? and ? limit ?
searchRule======================={limit=5, start=0, price_begin=2.0, price_end=111.0}
Hibernate: select productset0_.productsetid as products1_9_, productset0_.name as name9_, productset0_.addprice as addprice9_, productset0_.addcommission as addcommi4_9_, productset0_.searchrule as searchrule9_, productset0_.distributorid as distribu6_9_ from product_set productset0_ where productset0_.productsetid=?
p searchRule=++++++++++++++++++++++++++++++++++++++{limit=5, start=0, price_begin=2.0, price_end=111.0}
############productSetServiceTarget####################com.blueishop.ishop.service.impl.ProductSetServiceImpl@14ae5cd
saveOrUpdate begin-----------------------------------------
saveOrUpdate end---------------------------------------
--------------------action--end-------------------------

saveOrUpdate begin,saveOrUpdate end是dao实现中saveOrUpdate 语句的前后输出内容。

82636
2008-05-19 10:36

第二个action 代码:

public String update (){
		if(distributorid!=null){
			productSet.setDistributorid(distributorid);
		}
		System.out.println(productSet);
		double ac = productSet.getAddCommission();
		System.out.println("ac=================================="+ac);
		String id = productSet.getProductsetid();
		System.out.println(id+"---------------------id---------------------");

		ProductSet productSet1 = new ProductSet();
		productSet1 = productSetServiceTarget.findById(id);
		System.out.println("productSet1------------------------"+productSet1);
		productSet.setAddCommission(ac);
		System.out.println("----------------1 save or update---------------");
		productSetServiceTarget.merge(productSet);
		System.out.println("----------------2 save end------------");
		productSetServiceTarget.delete(productSet1);
		System.out.println("-------------------3-delete------------");
		return Common.STRUTS_SUCCESS;
	}

控制台输出的内容:

02:21:40,906 ERROR ParametersInterceptor:204 - ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'Submit' on 'class com.blueishop.ishop.action.distributor.ProductSetAction: Error setting expression 'Submit' with value '[Ljava.lang.String;@f45732'
02:21:40,953 ERROR ParametersInterceptor:204 - ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'Submit' on 'class com.blueishop.ishop.action.distributor.ProductSetAction: Error setting expression 'Submit' with value '[Ljava.lang.String;@f45732'
com.blueishop.ishop.entity.ProductSet@17df9ec[productsetid=402881f719cbaab50119cbb33cac0001]
ac==================================4.0
402881f719cbaab50119cbb33cac0001---------------------id---------------------
Hibernate: select productset0_.productsetid as products1_9_, productset0_.name as name9_, productset0_.addprice as addprice9_, productset0_.addcommission as addcommi4_9_, productset0_.searchrule as searchrule9_, productset0_.distributorid as distribu6_9_ from product_set productset0_ where productset0_.productsetid=?
productSet1------------------------com.blueishop.ishop.entity.ProductSet@1c98360[productsetid=402881f719cbaab50119cbb33cac0001]
----------------1 save or update---------------
merge begin====================================
merge end=====================================
----------------2 save end------------
-------------------3-delete------------
Hibernate: update product_set set name=?, addprice=?, addcommission=?, searchrule=?, distributorid=? where productsetid=?
Hibernate: delete from product_set where productsetid=?
Hibernate: select productset0_.productsetid as products1_9_, productset0_.name as name9_, productset0_.addprice as addprice9_, productset0_.addcommission as addcommi4_9_, productset0_.searchrule as searchrule9_, productset0_.distributorid as distribu6_9_ from product_set productset0_