I have One-To-Many relationship, here is my code
@Entity
@Table(name = \"catalog\")
public class Catalog {
@Id
@GeneratedValue(strategy = GenerationType
Here is my solution for this task with Hibernate. I marked hibernate releation with @JsonIgnore and use custom field for jackson, in which I check if the field is loaded. If you need serialize collection to json then you should manualy call collection getter during hibernate transaciton.
@JsonIgnore
@OneToMany(mappedBy = "myorder")
private List orderItems = new ArrayList<>();
@JsonProperty(value = "order_items", access = JsonProperty.Access.READ_ONLY)
private List getOrderItemsList() {
if(Hibernate.isInitialized(this.relatedDictionary)){
return this.relatedDictionary;
} else{
return new ArrayList<>();
}
}
@JsonProperty(value = "order_items", access = JsonProperty.Access.WRITE_ONLY)
private void setOrderItemsList(List orderItems) {
this.orderItems = orderItems;
}