我的Spring Rest API应用程序存在问题。
我有3个这样的实体:
Geometry.java
@Data
@Entity
@Table(name="sw_geometries")
public class Geometry{
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Geometry_Generator")
@SequenceGenerator(name="Geometry_Generator", sequenceName = "Geometry_Sequence")
private long id;
@OneToMany(mappedBy="geometry",
cascade= CascadeType.ALL, fetch=FetchType.LAZY)
private List<Multi> multies = new ArrayList<Multi>();
}
Multi.java
@Data
@Entity
@Table(name="sw_multis")
public class Multi{
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Multi_Generator")
@SequenceGenerator(name="Multi_Generator", sequenceName = "Multi_Sequence")
private long id;
@ManyToOne @JoinColumn(name="geometry_id")
private Geometry geometry;
@Column(name="geometry_id", updatable=false,insertable=false)
private Long geometryId;
@OneToMany(mappedBy="multi",
cascade= CascadeType.ALL,fetch=FetchType.LAZY)
private List<Location> locations = new ArrayList<Location>();
}
Location.java
import lombok.Data;
import javax.persistence.*;
@Data
@Entity
@Table(name="sw_locations")
public class Location {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Location_Generator")
@SequenceGenerator(name="Location_Generator", sequenceName = "Location_Sequence")
private Long id;
@ManyToOne@JoinColumn(name="multi_id")
private Multi multi;
@Column(name="multi_id", updatable=false,insertable=false)
private Long multiId;
Point.java <br>
@Embedded
private Point point;
public boolean isEmpty() {
boolean hasNoPoint = (point == null);
boolean hasNoPointCoord = (point !=null & point.getLatitude() ==null && point.getLongitude() == null);
return hasNoPoint || hasNoPointCoord;
}
@Override
public String toString() {
return "Location [point=" + point.toString() + "]";
}
}
Point.java
@Data
@Embeddable
public class Point {
@Column(name = "latitude")
private Double latitude;
@Column(name = "longitude")
private Double longitude;
@Column(name = "x")
private Float x;
@Column(name = "y")
private Float y;
}
当我使用sysout打印我的对象的结果时,一切似乎都没问题,我可以看到为每个多重打印的位置(Overrided toString)
但是当我使用rest客户端显示结果jsonI时,发现没有显示位置。
有什么想法吗?