我试图在数据库中进行简单选择,但出现此错误:
Failure while trying to resolve exception [org.springframework.http.converter.HttpMessageNotWritableException]
要创建多对多关系,我遵循以下响应:https://stackoverflow.com/a/32920550/10025420并且我的表还可以。
CommunityLine.java
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "community_line_seq")
@JsonBackReference
@SequenceGenerator(name = "community_line_seq", sequenceName = "community_line_seq", allocationSize = 1)
private Long id;
@Column(name = "apiKey", updatable = true, nullable = false, unique = true, columnDefinition = "BINARY(16)")
@org.hibernate.annotations.Type(type = "org.hibernate.type.UUIDBinaryType")
private UUID apiKey;
@Column(name = "name")
private String name;
@ManyToOne
@JoinColumn(name = "cv_id")
private Instrument instrument;
@ManyToOne
@JoinColumn(name = "param_id")
private Param param;
@ManyToOne
@JoinColumn(name = "sample_type_id")
private SampleType sampleType;
@ManyToOne
@JoinColumn(name = "context_source_id")
private ContextSource contextSource;
@Column(name = "value")
private float value;
@JsonManagedReference
@OneToMany(mappedBy = "node", fetch = FetchType.EAGER)
private List<CommunityLineNodeRelation> nodes;
// Getters and constructors
Node.java
@Entity
@Table(name="node")
public class Node {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "node_seq")
@SequenceGenerator(name = "node_seq", sequenceName = "node_seq", allocationSize = 1)
@JsonBackReference
private Long id;
@Column(name = "apiKey", updatable = false, nullable = false, unique=true, columnDefinition = "BINARY(16)")
@org.hibernate.annotations.Type(type="org.hibernate.type.UUIDBinaryType")
private UUID apiKey;
@Column
private String country;
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public UUID getApiKey() {
return apiKey;
}
public void setApiKey(UUID apiKey) {
this.apiKey = apiKey;
}
@Column(name = "NAME", length = 50, unique = true)
@NotNull
private String name;
@OneToMany(mappedBy="node")
private List<DataSource> dataSource;
@OneToMany(mappedBy="node", cascade=CascadeType.ALL)
private List<User> users;
public List<User> getUsers() {
return users;
}
@JsonBackReference
@OneToMany(mappedBy = "communityLine", cascade = CascadeType.ALL)
private List<CommunityLineNodeRelation> communityLines;
//getters and setters
CommunityLineNodeRelation.java
@Entity
@Table(name = "community_line_node")
public class CommunityLineNodeRelation implements Serializable {
@Id
@ManyToOne (fetch = FetchType.EAGER)
@JsonManagedReference
@JoinColumn(name = "community_line_id", referencedColumnName = "id")
private CommunityLine communityLine;
@Id
@ManyToOne (fetch = FetchType.EAGER)
@JsonManagedReference
@JoinColumn(name = "node_id", referencedColumnName = "id")
private Node node;
@Column (name = "is_active")
private boolean isActive;
CommunityLineNodeId.java
public class CommunityLineNodeId implements Serializable {
private Long communityLine;
private Long node;
回购
@Repository
public interface CommunityLineRepository extends CrudRepository<CommunityLine, Long> {
public List<CommunityLine> findAll();
}
哪个类需要存储库?我已经尝试使用CommunityLine和关系类。
为什么会出现此错误?
编辑:我已经设法避免了该错误,但是现在JSON缺少node属性,因此选择有效,因为我可以在服务器控制台中打印该节点。