首页 > 代码库 > hibernate+mysql关联映射师遇到java.lang.StackOverflowError异常
hibernate+mysql关联映射师遇到java.lang.StackOverflowError异常
hibernate+mysql关联映射师遇到java.lang.StackOverflowError异常
原因在进行关联映射时在多的一方的toString方法中有对属性对应的一的一方的输出
比如:
一的一方:
@Entity
@Table(name = "app",schema = "", catalog = "game")
public class AppEntity {
@Id
@Column(name = "appId")
private String appId;
@Basic
@Column(name = "appName")
private String appName;
@Basic
@Column(name = "appdesc")
private String appdesc;
@Basic
@Column(name = "provider")
private String provider;
@Basic
@Column(name = "version")
private String version;
@Basic
@Column(name="postTime")
private Long postTime;
@Basic
@Column(name = "updateTime")
private Long updateTime;
@OneToMany(mappedBy = "appEntity",fetch = FetchType.EAGER)
private Set<ProductEntity> productEntities;
@OneToMany(mappedBy = "appEntity",fetch = FetchType.LAZY)
private Set<OrdersEntity> ordersEntities;
多的一方
@Entity
@Table(name = "product", schema = "" , catalog = "game")
@IdClass(ProductEntityPK.class)
public class ProductEntity {
@Id
@Column(name = "appId")
private String appId;
@Id
@GeneratedValue
@Column(name = "productId")
private long productId;
@Basic
@Column(name = "productName")
private String productName;
@Basic
@Column(name = "productDesc")
private String productDesc;
@Basic
@Column(name = "price")
private long price;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="appId",insertable = false, updatable = false)
private AppEntity appEntity;
@Override
public String toString() {
return "ProductEntity{" +
"appId=‘" + appId + ‘\‘‘ +
", productId=" + productId +
", productName=‘" + productName + ‘\‘‘ +
", productDesc=‘" + productDesc + ‘\‘‘ +
", price=" + price
", appEntity=" + appEntity +
‘}‘;
}
解决办法:将productEntity的toString方法中去掉 ", appEntity=" + appEntity +
hibernate+mysql关联映射师遇到java.lang.StackOverflowError异常
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。