myeclipse SSH 下报错 attempt to create saveOrUpdate event with null entity
流程往ordercargo表中增加1条记录表中含2个外键orderId和cargoId需要从order和cargo表中取得jsp-action-service-dao的流...
流程 往ordercargo表中增加1条记录 表中含2个外键orderId 和 cargoId 需要从 order 和 cargo表中取得 jsp-action-service-dao 的流程
代码如下
jsp
<s:form action="addOrderCargo" theme="simple">
<s:select name="orderCargo.cargoId" list="#request.cargoIdMap" label="物品类别" listKey="key"
listValue="value" headerKey="0" headerValue="选择类别"></s:select>
<s:select name="orderCargo.orderId" list="#request.orderIdMap" label="物品类别" listKey="key"
listValue="value" headerKey="0" headerValue="选择类别1"></s:select>
<s:textfield name="orderCargo.orderCargoNum" label="订购数量"></s:textfield>
<s:textfield name="orderCargo.orderCargoSortPrice" label="价格"></s:textfield>
<s:textfield name="orderCargo.qualityAdminId" label="质量管理员ID"></s:textfield>
<s:textfield name="orderCargo.qualityCargo" label="产品质量"></s:textfield>
<s:textfield name="orderCargo.qualityInfo" label="质量信息"></s:textfield>
<s:textfield name="orderCargo.qualityTime" label="检测日期"></s:textfield>
<s:textfield name="orderCargo.stockAdminId" label="stockAdminId"></s:textfield>
<s:textfield name="orderCargo.stockTypeId" label="stockTypeId"></s:textfield>
<s:textfield name="orderCargo.inStockTime" label="inStockTime"></s:textfield>
<s:textfield name="orderCargo.cargoProTime" label="cargoProTime"></s:textfield>
<s:submit></s:submit>
</s:form>
action
// 外键
public String toAddCargo() {
List<Cargo> cargoIdList = orderCargoService.findAllCargoId();
HashMap<Integer, String> cargoIdMap = new LinkedHashMap<Integer, String>();
for (Cargo a : cargoIdList) {
cargoIdMap.put(a.getCargoId(), a.getCargoName());
}
System.out.print(cargoIdMap.get(1));
request.setAttribute("cargoIdMap", cargoIdMap);
return SUCCESS;
}
public String toAddOrder() {
List<Order> orderIdList = orderCargoService.findAllOrderId();
HashMap<Integer, String> orderIdMap = new LinkedHashMap<Integer, String>();
for (Order a : orderIdList) {
orderIdMap.put(a.getOrderId(), a.getOrderTime());
}
System.out.print(orderIdMap.get(1));
request.setAttribute("orderIdMap", orderIdMap);
return SUCCESS;
}
public String addOrderCargo() {
orderCargoService.addOrderCargo(orderCargo);
return SUCCESS;
}
service
public void addOrderCargo(OrderCargo transientInstance) {
orderCargoDAO.save(transientInstance);
}
//根据ID查找所有物品和订单
public List findAllOrderId(){
return orderDAO.findAll();
}
public List findAllCargoId(){
return cargoDAO.findAll();
}
public void addOrderCargo(OrderCargo transientInstance) {
orderCargoDAO.save(transientInstance);
}
dao
public void save(OrderCargo transientInstance) {
log.debug("saving OrderCargo instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
struts 配置
<action name="addOrderCargo" class="OrderCargoAction" method="addOrderCargo">
<result name="success" >qualityadmin/addOrderCargo.jsp
</result>
</action>
spring中的配置
<bean id="OrderCargoDAO" class="com.logistics.po.OrderCargoDAO"
scope="prototype">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="OrderCargoService" class="com.logistics.service.OrderCargoService"
scope="prototype">
<property name="orderCargoDAO">
<ref bean="OrderCargoDAO" />
</property>
<property name="orderDAO">
<ref bean="OrderDAO"/>
</property>
<property name="cargoDAO">
<ref bean="CargoDAO"/>
</property>
</bean>
<bean id="OrderCargoAction" class="com.logistics.action.OrderCargoAction"
scope="prototype">
<property name="orderCargoService">
<ref bean="OrderCargoService" />
</property>
</bean>
debug显示 cargoorder 和dao中transientInstance 是null 没能传值 求高手解答 展开
代码如下
jsp
<s:form action="addOrderCargo" theme="simple">
<s:select name="orderCargo.cargoId" list="#request.cargoIdMap" label="物品类别" listKey="key"
listValue="value" headerKey="0" headerValue="选择类别"></s:select>
<s:select name="orderCargo.orderId" list="#request.orderIdMap" label="物品类别" listKey="key"
listValue="value" headerKey="0" headerValue="选择类别1"></s:select>
<s:textfield name="orderCargo.orderCargoNum" label="订购数量"></s:textfield>
<s:textfield name="orderCargo.orderCargoSortPrice" label="价格"></s:textfield>
<s:textfield name="orderCargo.qualityAdminId" label="质量管理员ID"></s:textfield>
<s:textfield name="orderCargo.qualityCargo" label="产品质量"></s:textfield>
<s:textfield name="orderCargo.qualityInfo" label="质量信息"></s:textfield>
<s:textfield name="orderCargo.qualityTime" label="检测日期"></s:textfield>
<s:textfield name="orderCargo.stockAdminId" label="stockAdminId"></s:textfield>
<s:textfield name="orderCargo.stockTypeId" label="stockTypeId"></s:textfield>
<s:textfield name="orderCargo.inStockTime" label="inStockTime"></s:textfield>
<s:textfield name="orderCargo.cargoProTime" label="cargoProTime"></s:textfield>
<s:submit></s:submit>
</s:form>
action
// 外键
public String toAddCargo() {
List<Cargo> cargoIdList = orderCargoService.findAllCargoId();
HashMap<Integer, String> cargoIdMap = new LinkedHashMap<Integer, String>();
for (Cargo a : cargoIdList) {
cargoIdMap.put(a.getCargoId(), a.getCargoName());
}
System.out.print(cargoIdMap.get(1));
request.setAttribute("cargoIdMap", cargoIdMap);
return SUCCESS;
}
public String toAddOrder() {
List<Order> orderIdList = orderCargoService.findAllOrderId();
HashMap<Integer, String> orderIdMap = new LinkedHashMap<Integer, String>();
for (Order a : orderIdList) {
orderIdMap.put(a.getOrderId(), a.getOrderTime());
}
System.out.print(orderIdMap.get(1));
request.setAttribute("orderIdMap", orderIdMap);
return SUCCESS;
}
public String addOrderCargo() {
orderCargoService.addOrderCargo(orderCargo);
return SUCCESS;
}
service
public void addOrderCargo(OrderCargo transientInstance) {
orderCargoDAO.save(transientInstance);
}
//根据ID查找所有物品和订单
public List findAllOrderId(){
return orderDAO.findAll();
}
public List findAllCargoId(){
return cargoDAO.findAll();
}
public void addOrderCargo(OrderCargo transientInstance) {
orderCargoDAO.save(transientInstance);
}
dao
public void save(OrderCargo transientInstance) {
log.debug("saving OrderCargo instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
struts 配置
<action name="addOrderCargo" class="OrderCargoAction" method="addOrderCargo">
<result name="success" >qualityadmin/addOrderCargo.jsp
</result>
</action>
spring中的配置
<bean id="OrderCargoDAO" class="com.logistics.po.OrderCargoDAO"
scope="prototype">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="OrderCargoService" class="com.logistics.service.OrderCargoService"
scope="prototype">
<property name="orderCargoDAO">
<ref bean="OrderCargoDAO" />
</property>
<property name="orderDAO">
<ref bean="OrderDAO"/>
</property>
<property name="cargoDAO">
<ref bean="CargoDAO"/>
</property>
</bean>
<bean id="OrderCargoAction" class="com.logistics.action.OrderCargoAction"
scope="prototype">
<property name="orderCargoService">
<ref bean="OrderCargoService" />
</property>
</bean>
debug显示 cargoorder 和dao中transientInstance 是null 没能传值 求高手解答 展开
2个回答
展开全部
public String addOrderCargo() {
orderCargoService.addOrderCargo(orderCargo);
return SUCCESS;
}
public void addOrderCargo(OrderCargo transientInstance) {
orderCargoDAO.save(transientInstance);
}
dao
public void save(OrderCargo transientInstance) {
你这个dao中的transientInstance 是从action中的orderCargo直接传过来的
由于你action代码不全,也看不出来orderCargo是什么,你自己看看吧
orderCargoService.addOrderCargo(orderCargo);
return SUCCESS;
}
public void addOrderCargo(OrderCargo transientInstance) {
orderCargoDAO.save(transientInstance);
}
dao
public void save(OrderCargo transientInstance) {
你这个dao中的transientInstance 是从action中的orderCargo直接传过来的
由于你action代码不全,也看不出来orderCargo是什么,你自己看看吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询