Invocation of init method failed could not instantiate test object

来源:互联网 发布:ubuntu不能切换输入法 编辑:程序博客网 时间:2024/05/17 10:56

Invocation of init method failed; nested exception is

org.hibernate.InstantiationException: could not instantiate test object com.yjiasoft.table.StationInfo

这里做的是双向关联
错误实体类:
public class StationInfo implements java.io.Serializable {

// Fields

private Integer id;
private String stationName;
private String code;
private String linkman;
private String comTel;
private String cellPhone;
private Integer levelFlag;
private Integer qualityFlag;
private Integer speedFlag;
private String remark;
private Integer groupId;
private String areaAxis;
private Integer ztxtLeft;
private Integer ztxtTop;
private River river = new River();

//getter
//setter
}

public class River implements java.io.Serializable {

// Fields

private Integer id;
//private Integer stcdt;
private String name;
private double lower;
private double high;
private double minflux;
private double maxflux;
private StationInfo station =new StationInfo();
//getter
//setter
}


解决方法:定义结构会导致死循环,结果堆栈溢出,所以 在定义时两个成员类不要实例化,可初始

化为null。
改成如下:

public class StationInfo implements java.io.Serializable {

// Fields

private Integer id; 
///.....////
private Integer ztxtTop;
private River river ;

//getter
//setter
}

public class River implements java.io.Serializable {

// Fields

private Integer id;
///.....////
private double maxflux;
private StationInfo station;
//getter
//setter
}