action里的代码如下:测试发现程序能够输出System.out.println(ChooseGoods[i]+"////");但 god = gdi.selectById(ChooseGoods[i]);没有执行,不知道为什么会停在这!
Hibernate使用的标签,这里问什么会报映射异常呢....
刚学习,望指导,谢谢!
package com.action;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.dao.imple.GoodsDaoImple;
import com.dao.imple.GustorderDaoImple;
import com.dao.imple.OrderDetailsDaoImple;
import com.entity.Goods;
import com.opensymphony.xwork2.ActionContext;
public class OrderAction {
GoodsDaoImple gdi = new GoodsDaoImple();
GustorderDaoImple odi = new GustorderDaoImple();
OrderDetailsDaoImple oddi = new OrderDetailsDaoImple();
private Goods god = new Goods();
private int[] gid;
private String[] amount;
private String name;
private String address;
private int[] ChooseGoods;
public Goods getGod() {
return god;
}
public void setGod(Goods god) {
this.god = god;
}
public int[] getGid() {
return gid;
}
public void setGid(int[] gid) {
this.gid = gid;
}
public String[] getAmount() {
return amount;
}
public void setAmount(String[] amount) {
this.amount = amount;
}
private List list = new ArrayList() ;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int[] getChooseGoods() {
return ChooseGoods;
}
public void setChooseGoods(int[] chooseGoods) {
ChooseGoods = chooseGoods;
}
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
public String execute(){
for (int i = 0;i<ChooseGoods.length;i++){
System.out.println(ChooseGoods.length);
System.out.println(ChooseGoods[i]+"////");
god = gdi.selectById(ChooseGoods[i]);
System.out.println("商品名称是:"+god.getGoodsname());
list.add(god);
System.out.println("里面的list的长度是:"+list.size());
}
System.out.println("list的长度是:"+list.size());
Map session = ActionContext.getContext().getSession();
session.put("list", list);
return "success";
}
如下是错误:
type Exception report
message
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.lang.reflect.InvocationTargetException
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
...........................................太多,后面的错误信息省了...........................
.........................................
root cause
java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I
org.hibernate.hql.ast.HqlSqlWalker.generatePositionalParameter(HqlSqlWalker.java:896)
org.hibernate.hql.antlr.HqlSqlBaseWalker.parameter(HqlSqlBaseWalker.java:4819)
.........................................
....................................... ...........................................太多,后面的错误信息省了...........................
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.67 logs.
下面是查询方法的实体类:
package com.entity;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
- Goods entity. @author MyEclipse Persistence Tools */ @Entity @Table(name = "goods", catalog = "ordersystem") public class Goods implements java.io.Serializable {
// Fields
private Integer gid;
private String goodsname;
private Float goodsprice;
private String goodsdesc;
private String goodsmanufacturer;
private Set orderdetailses = new HashSet(0);
// Constructors
/** default constructor */
public Goods() {
}
public Goods(Integer gid, String goodsname, Float goodsprice,
String goodsdesc, String goodsmanufacturer) {
super();
this.gid = gid;
this.goodsname = goodsname;
this.goodsprice = goodsprice;
this.goodsdesc = goodsdesc;
this.goodsmanufacturer = goodsmanufacturer;
}
/** minimal constructor */
public Goods(String goodsname, Float goodsprice) {
this.goodsname = goodsname;
this.goodsprice = goodsprice;
}
/** full constructor */
public Goods(String goodsname, Float goodsprice, String goodsdesc,
String goodsmanufacturer, Set orderdetailses) {
this.goodsname = goodsname;
this.goodsprice = goodsprice;
this.goodsdesc = goodsdesc;
this.goodsmanufacturer = goodsmanufacturer;
this.orderdetailses = orderdetailses;
}
// Property accessors
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "gid", unique = true, nullable = false)
public Integer getGid() {
return this.gid;
}
public void setGid(Integer gid) {
this.gid = gid;
}
@Column(name = "goodsname", nullable = false, length = 10)
public String getGoodsname() {
return this.goodsname;
}
public void setGoodsname(String goodsname) {
this.goodsname = goodsname;
}
@Column(name = "goodsprice", nullable = false, precision = 12, scale = 0)
public Float getGoodsprice() {
return this.goodsprice;
}
public void setGoodsprice(Float goodsprice) {
this.goodsprice = goodsprice;
}
@Column(name = "goodsdesc", length = 20)
public String getGoodsdesc() {
return this.goodsdesc;
}
public void setGoodsdesc(String goodsdesc) {
this.goodsdesc = goodsdesc;
}
@Column(name = "goodsmanufacturer", length = 10)
public String getGoodsmanufacturer() {
return this.goodsmanufacturer;
}
public void setGoodsmanufacturer(String goodsmanufacturer) {
this.goodsmanufacturer = goodsmanufacturer;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "goods")
public Set getOrderdetailses() {
return this.orderdetailses;
}
public void setOrderdetailses(Set orderdetailses) {
this.orderdetailses = orderdetailses;
}
}