Hibernate: delete from tblOrderType where OrderTypeNo in (OrderType_18603477058015)
2012-07-03 14:47:41  SQL Error: 207, SQLState: S0001
2012-07-03 14:47:41  列名 'OrderType_18603477058015' 无效。
OrderType.hbm.xml 配置<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.angenic.order.bean.OrderType" table="tblOrderType" batch-size="20">
<id name="orderTypeNo" type="java.lang.String" column="OrderTypeNo"/>
<property name="name" type="java.lang.String" column="Name"/>
<property name="details" type="java.lang.String" column="Details"/>
<property name="creationDate" type="java.util.Date" column="CreationDate"/>

</class>

</hibernate-mapping>OrderType.javapackage com.angenic.order.bean;import java.io.Serializable;
import java.util.Date;import com.angenic.common.hibernate.bean.Entity;@SuppressWarnings("serial")
public class OrderType implements Entity, Serializable {
private String orderTypeNo;
private String name;
private String details;
private Date creationDate; public String getOrderTypeNo() {
return orderTypeNo;
} public void setOrderTypeNo(String orderTypeNo) {
this.orderTypeNo = orderTypeNo;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getDetails() {
return details;
} public void setDetails(String details) {
this.details = details;
} public Date getCreationDate() {
return creationDate;
} public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
} public Serializable getId() {
return orderTypeNo;
}}
OrderTypeAction  delete方法继承了,所以不用写了。

package com.angenic.order.web;import com.angenic.common.hibernate.search.MyCriteria;
import com.angenic.common.hibernate.search.MyCriteriaFactory;
import com.angenic.common.service.BaseService;
import com.angenic.common.struts.web.BaseActionSupport;
import com.angenic.order.bean.OrderType;
import com.angenic.order.service.OrderTypeService;@SuppressWarnings("serial")
public class OrderTypeAction extends BaseActionSupport<OrderType> {
OrderTypeService orderTypeService = null;
OrderType orderType = null;

@Override
public String list() {
MyCriteria criteria = MyCriteriaFactory.createCriteria(OrderType.class);
request.put("entityList",orderTypeService.findObjects(criteria, getPage()));
return LIST;
}

@Override
public String save() {
if(orderType.getOrderTypeNo() != null && !"".equals(orderType.getOrderTypeNo())){
orderTypeService.updateObject(orderType);
}else{
orderType.setOrderTypeNo(String.valueOf(OrderType.class.getSimpleName()+"_"+System.nanoTime()));
orderTypeService.saveObject(orderType);
}
return VIEW;
} @Override
protected BaseService<OrderType> getBaseService() {
return this.orderTypeService;
}
@Override
protected void setEntity(OrderType obj) {
this.orderType = obj;

}
@Override
protected OrderType getEntity() {
return this.orderType;
} public OrderTypeService getOrderTypeService() {
return orderTypeService;
}
public void setOrderTypeService(OrderTypeService orderTypeService) {
this.orderTypeService = orderTypeService;
}
public OrderType getOrderType() {
return orderType;
}
public void setOrderType(OrderType orderType) {
this.orderType = orderType;
}
}

解决方案 »

  1.   

    <id name="orderTypeNo" type="java.lang.String" column="OrderTypeNo"/> 
    主键是自增还是什么类型,怎么没有设置
      

  2.   


    主键 不是自增的,已经写死了.
    String类型。
      

  3.   

    你这样写
    <id name="orderTypeNo" type="java.lang.String">
      <column length="20" name="OrderTypeNo"/>
      <generator class="uuid">  
      </id>
      

  4.   

    delete方法在哪调用的?没粘出来,debug看一下传给delete的参数是不是有问题。
      

  5.   

    谢谢各位,已经解决了。 最底层的方法不完善,修改了,就好了。
        
        public void deleteObject(T obj) {
    try {
        if (getBaseValidate().validateDelete(new Serializable[] { obj.getId() })) {
         getHibernateDAO().delete(obj);
            this.addMessage("common.message.delete.success", new String[] { getText(obj.getClass().getName()) });
        }
    }catch (MyErrorLocalMessageException e) {
        this.clearResults();
        throw e;
    }
        }    public void deleteObject(Serializable id) {
    try {
        if (getBaseValidate().validateDelete(new Serializable[] { id })) {
         getHibernateDAO().delete(id);
            this.addMessage("common.message.delete.success", new String[] { getText(getHibernateDAO().getEntityName()) });
        }
    } catch (MyErrorLocalMessageException e) {
        this.clearResults();
        throw e;
    }
        }    public void deleteObjects(Serializable[] ids) {
    try {
        if (getBaseValidate().validateDelete(ids)) {
         getHibernateDAO().deletes(ids);
        }
    } catch (MyErrorLocalMessageException e) {
        this.clearResults();
        throw e;
    }
        }
        
        public void deleteObject(Serializable[] ids) {
    try {
        if (getBaseValidate().validateDelete(ids)) {
         getHibernateDAO().delete(ids);
        }
    } catch (MyErrorLocalMessageException e) {
        this.clearResults();
        throw e;
    }
        }