У меня есть проблема, связанная с POST-объектом JSON для сохранения данных в загрузочном приложении Spring.
Объекты выглядят так:
@Entity
@Table(name = "extended_company_info")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ExtendedCompanyInfo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@Column(name = "city", nullable = false)
private String city;
@NotNull
@Column(name = "url", nullable = false)
private String url;
@NotNull
@Column(name = "phone", nullable = false)
private String phone;
@OneToMany(mappedBy = "extendedCompanyInfo", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<AddressInfo> addresses = new HashSet<>();
@OneToOne
@JoinColumn(unique = true)
@JsonIgnore
private Company company;
//… getters setters
}
Таблица выглядит следующим образом: extended_company_info (id, город, URL, телефон)
@Entity
@Table(name = “address_info")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class AddressInfo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@Column(name = “address”, nullable = false)
private String address;
@NotNull
@Enumerated(EnumType.STRING)
@Column(name = “address_type", nullable = false)
private AddressType addressType;
@JsonIgnore
@ManyToOne(optional = false)
@JoinColumn(name="extended_company_info_id")
@NotNull
private ExtendedCompanyInfo extendedCompanyInfo;
//… getters setters
}
Таблица выглядит следующим образом: address_info (id, address, address_type, extended_company_info_id)
public enum AddressType {
ADDRESS1, ADDRESS2, ADDRESS3
}
JSON-объект, который я помещаю в POST, выглядит следующим образом:
{
“city”: “city”,
“url”: “http://www.url.com”,
“phone”: “123456789”,
“addresses”: [{
“address”: “address abcd”,
“addressType": “ADDRESS1”
}],
"company": {
"id": 1,
"name": “Company name“,
"shortName": “Company shortname“,
"customerNumber": "1234"
}
}
Но я получаю следующую ошибку:
Bad Request: Validation failed for classes [package.AddressInfo] during persist time for groups [javax.validation.groups.Default, ]
List of constraint violations:[ ConstraintViolationImpl{interpolatedMessage='may not be null', propertyPath= extendedCompanyInfo, rootBeanClass=class package.AddressInfo, messageTemplate='{javax.validation.constraints.NotNull.message}'}
Каким образом я должен структурировать extendedCompanyInfo в JSONобъект?
Чего мне не хватает?