码迷,mamicode.com
首页 > 数据库 > 详细

hibernate+mysql关联映射师遇到java.lang.StackOverflowError异常

时间:2017-05-27 16:09:04      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:pen   sql   post   解决办法   return   upd   etc   pid   str   

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异常

标签:pen   sql   post   解决办法   return   upd   etc   pid   str   

原文地址:http://www.cnblogs.com/sy-liu/p/6913160.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!