Invocation of init method failed could not instantiate test object

本文介绍了一个关于Hibernate在处理双向关联时出现的InstantiationException问题及解决方案。错误发生在StationInfo与River两个实体类互相引用并尝试实例化对方时。解决方法是避免在定义类时直接实例化关联对象,而应初始化为null。
摘要由CSDN通过智能技术生成

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
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值