我有自我参考课
@Entity
@Table(name = "contacts")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "contacts")
public class Contacts implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "username")
private String username;
@Column(name = "password_smartlpc")
private String password;
@Column(name = "full_name")
private String fullName;
@ManyToOne
private Contacts companyContact;
}但为了我的一份数据库记录
id full_name username password company_contact_id
5 JAK movies abc xyz 5此记录以company_contact_id作为其自引用( self id.Which ),而检索则进入自引用循环。
Enter: com.fps.web.rest.errors.ExceptionTranslator.processRuntimeException()
with argument[s] =
[org.springframework.http.converter.HttpMessageNotWritableException: Could not
write content: Direct self-reference leading to cycle (through reference
chain: java.util.UnmodifiableRandomAccessList[2]-
>com.fps.domain.Contacts["companyContact"]-
>com.fps.domain.Contacts["companyContact"]); nested exception is
com.fasterxml.jackson.databind.JsonMappingException: Direct self-reference
leading to cycle (through reference chain:
java.util.UnmodifiableRandomAccessList[2]-
>com.fps.domain.Contacts["companyContact"]-
>com.fps.domain.Contacts["companyContact"])] 我试过了
(fetch = FetchType.LAZY) = gives same error as above.
@JsonIgnore : removes error but does not retrieves Company_Contact_id
@JsonManagedReference @JsonBackReference same as above.不幸的是,我不能更改数据库或修改it.Since,它的legacy.Any,我还可以尝试更多的东西吗?谢谢
发布于 2017-10-29 09:41:18
尝试在使用DTO中使用JHipster,您将获得对JSON序列化的更多控制,而不是简单地公开您的实体,特别是当您受到遗留数据库模式的限制时。
https://stackoverflow.com/questions/46994637
复制相似问题