RHANOU1987 2016-10-14 14:15 采纳率: 0%
浏览 865
已结题

struts2 与Hibernate编程异常,求解决!!!

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;
}

}

  • 写回答

2条回答 默认 最新

  • RHANOU1987 2016-10-14 14:26
    关注

    自己顶
    代码中god = gdi.selectById(ChooseGoods[i]);这个方法是没问题的,Junit Test是没问题的!,
    //查询勾选的商品信息
    @Override
    public Goods selectById(int gid) {
    Session session = HibernateSessionFactory.getSession();
    String hql = "select g from Goods g where g.gid = ?";
    Query q = session.createQuery(hql);
    q.setParameter(0, gid);
    Goods g = (Goods) q.uniqueResult();
    session.close();
    return g;
    }

    不知道是不是Goods这个类在这里不能接受?

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集