我正在使用resteasy jakson提供3.0.17,这是我的对象结构。
@SuppressWarnings("serial")
@Entity
@Getter
@Setter
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class,
property = "@id")
public class Product implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_seq")
@SequenceGenerator(name = "id_seq", sequenceName = "id_seq")
private Long productId;
@Basic
private String productName;
@Basic
private String type;
@Basic
private String productCode;
@Basic
private String outputName;
@Basic
private String creationMethod;
@LazyCollection(LazyCollectionOption.FALSE)
@OneToMany(mappedBy = "primaryKey.product")
@JsonManagedReference
private Set<ProductDataElement> productDataElements = new HashSet<>();
}
@SuppressWarnings("serial")
@Entity
@Table(schema = "product", name = "productdataelement")
// To cater to additional column in the mapping table
@AssociationOverrides({
@AssociationOverride(name = "primaryKey.product", joinColumns = @JoinColumn(name = "productId")),
@AssociationOverride(name = "primaryKey.dataElement", joinColumns = @JoinColumn(name = "dataElementId")),
})
@Setter
public class ProductDataElement implements Serializable {
@EmbeddedId
@JsonUnwrapped
private ProductDataElementId primaryKey;
@Basic
private Long rowLimit;
}
@SuppressWarnings("serial")
@Getter
@Setter
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
@Embeddable
public class ProductDataElementId implements Serializable {
@JsonBackReference
@ManyToOne(cascade = CascadeType.ALL)
private Product product;
@JsonBackReference
@ManyToOne(cascade = CascadeType.ALL)
private DataElement dataElement;
}
当我为特定产品执行JPA查询时,我在服务器端获得包含productDataElements
集合的嵌套结构,但是当这些数据通过REST webservice调用发送到浏览器时,我获得了具有空对象的集合ProductDataElement
对象。任何线索可以获得完整对象的可能解决方案?
答案 0 :(得分:0)
现在解决了..
我不得不加入
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class,
property = "@id")
在ProductDataElementId和ProductDataElement上使其正常工作。