首先,我确定我遇到的问题在baidu没有找到解决方案.
现有2个表Customer,Account两个表,他们之间是一对多的关系 , 一个客户有多个账户.定义2个实体类如下:
public class Customer implements Serializable{
private String custId;
.......
private Set<Account> accounts = new HashSet<Account>(0);
@OneToMany(cascade==CascadeType.ALL,mappedby="customer")
public Set<Account> getAccounts{ .... }
}
public class Account implements Serializable{
private String accountId;
....
private Customer customer;
@ManyToOne
@JoinColumn(name="customerId")
public Customer getCustomer{ .... }
}
现在想通过hql查询所有客户号为1的账号
hql = "from Account t where t.customerId='1'"
利用gson把查询的所有账户记录序列化为json字符串
运行后报异常,异常信息为 发现存在循环引用
circular reference found:.....
请问些问题该如何解决?