Я пытаюсь вставить данные в три разные таблицы с помощью репозитория JPA с приложением весенней загрузки. для этой цели я использовал аннотации @onetomany и @manytoone в этих трех классах:
- HouseHold
- OwnerDetails
- HouseHoldMembers
, нокогда я пытаюсь вставить, я получаю следующую ошибку.
Hibernate:
select
*
from
household
where
sl_no = ?
2019-10-16 12:24:46.622 INFO 19380 --- [nio-8080-exec-1] c.o.a.a.s.FormServiceImpl : FormServiceImpl saveHouseDetailsWithBase64() is invoked : 234546674
Hibernate:
select
nextval ('house_id_seq')
Hibernate:
select
nextval ('owner_id_seq')
Hibernate:
select
nextval ('mem_id_seq')
Hibernate:
insert
into
household
(area, audio, district, east, gp_name, grid_no, house_dimension, house_photo, id, id_number, id_photo, Khatha_no, latitute, locality_name, longitute, map_photo, north, phone_num, pin, prop_details, prop_type, rent_amount, road_name, sl_no, south, servey_date, survey_no, surveyor_name, taluk, tenant, toilet_available, total_members, vacant_port, village_name, water_facility, west, hid)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate:
insert
into
ownerdetails
(age, education, gender, hid, idname, idnumber, name, oid)
values
(?, ?, ?, ?, ?, ?, ?, ?)
2019-10-16 12:24:46.832 WARN 19380 --- [nio-8080-exec-1] o.h.e.j.s.SqlExceptionHelper : SQL Error: 0, SQLState: 23502
2019-10-16 12:24:46.832 ERROR 19380 --- [nio-8080-exec-1] o.h.e.j.s.SqlExceptionHelper : ERROR: null value in column "hid" violates not-null constraint
Detail: Failing row contains (1, 10, education, male, adhaarcard1, 23424242343, name, null).
2019-10-16 12:24:46.840 ERROR 19380 --- [nio-8080-exec-1] o.h.i.ExceptionMapperStandardImpl : HHH000346: Error during managed flush [org.hibernate.exception.ConstraintViolationException: could not execute statement]
could not execute statement; SQL [n/a]; constraint [hid]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
2019-10-16 12:24:46.848 ERROR 19380 --- [nio-8080-exec-1] c.o.a.a.s.FormServiceImpl : could not execute statement; SQL [n/a]; constraint [hid]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
2019-10-16 12:24:46.849 INFO 19380 --- [nio-8080-exec-1] c.o.a.a.c.FormDataController : FormDataController saveHouseHold() request is completed.
HouseHold.java
@Entity
@Table(name = "household")
public class HouseHold implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "house_id_seq")
@SequenceGenerator(name = "house_id_seq", sequenceName = "house_id_seq", allocationSize = 1)
@Column(name = "hid")
private Long hid;
@NotNull
@Size(max = 100)
@Column(name = "district")
private String district;
@NotNull
@Size(max = 100)
@Column(name = "taluk")
private String taluk;
@NotNull
@Size(max = 100)
@Column(name = "village_name")
private String villageName;
@NotNull
@Column(name = "sl_no")
private Long slNo;
@NotNull
@Size(max = 100)
@Column(name = "Khatha_no")
private String khathaNo;
@NotNull
@Size(max = 50)
@Column(name = "locality_name")
private String localityName;
@NotNull
@Size(max = 50)
@Column(name = "prop_details")
private String propertyDetails;
@NotNull
@Size(max = 50)
@Column(name = "tenant")
private String tenant;
@NotNull
@Size(max = 200)
@Column(name = "house_dimension")
private String houseDimension;
@NotNull
@Size(max = 50)
@Column(name = "east")
private String east;
@NotNull
@Size(max = 50)
@Column(name = "west")
private String west;
@NotNull
@Size(max = 50)
@Column(name = "north")
private String north;
@NotNull
@Size(max = 50)
@Column(name = "south")
private String south;
@NotNull
@Digits(integer = 6, fraction = 2)
@Column(name = "rent_amount")
private BigDecimal rentAmount;
@NotNull
@Size(max = 100)
@Column(name = "vacant_port")
private String vacantPort;
@NotNull
@Size(max = 100)
@Column(name = "gp_name")
private String gpName;
@NotNull
@Size(max = 100)
@Column(name = "prop_type")
private String propertyType;
@NotNull
@Size(max = 100)
@Column(name = "road_name")
private String roadName;
@NotNull
@Column(name = "pin")
private Long pin;
@NotNull
@Column(name = "survey_no")
private Long surveyNo;
@NotNull
@Size(max = 250)
@Column(name = "grid_no")
private String gridNo;
@NotNull
@Size(max = 250)
@Column(name = "id_number")
private String idNumber;
@NotNull
@Size(max = 100)
@Column(name = "area")
private String area;
@NotNull
@Size(max = 3)
@Column(name = "toilet_available")
private String toiletAvailable;
@NotNull
@Size(max = 3)
@Column(name = "water_facility")
private String waterFacility;
@NotNull
@Column(name = "phone_num")
private Long phoneNumber;
@NotNull
@Column(name = "house_photo")
private String housephoto;
@NotNull
@Column(name = "id_photo")
private String idphoto;
@NotNull
@Column(name = "map_photo")
private String mapphoto;
@NotNull
@Column(name = "audio")
private String audio;
@NotNull
@Digits(integer = 3, fraction = 25)
@Column(name = "latitute")
private BigDecimal latitude;
@NotNull
@Digits(integer = 3, fraction = 25)
@Column(name = "longitute")
private BigDecimal longitude;
@NotNull
@Size(max = 100)
@Column(name = "surveyor_name")
private String surveyorName;
@Column(name = "servey_date")
@Temporal(TemporalType.TIMESTAMP)
private Date surveyDate;
@NotNull
@Size(max = 10)
@Column(name = "total_members")
private String totalMembers;
@NotNull
@Column(name = "id")
private Long id;
@JsonIgnore
@Transient
private String serveyStringDate;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "houseHold", fetch = FetchType.EAGER)
private List<OwnerDetails> ownerdetail = new ArrayList<>();
//default constructor
//parameterized constructor
//getter setter
OwnerDetails.java
@Entity
@Table(name = "ownerdetails")
public class OwnerDetails implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "owner_id_seq")
@SequenceGenerator(name = "owner_id_seq", sequenceName = "owner_id_seq", allocationSize = 1)
@Column(name = "oid")
private Long oid;
@NotNull
@Size(max = 100)
@Column(name = "name")
private String name;
@NotNull
@Size(max = 100)
@Column(name = "education")
private String education;
@NotNull
@Column(name = "age")
private int age;
@NotNull
@Size(max = 10)
@Column(name = "gender")
private String gender;
@NotNull
@Size(max = 100)
@Column(name = "idname")
private String idName;
@NotNull
@Size(max = 100)
@Column(name = "idnumber")
private String idNumber;
@JsonIgnore
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "hid", referencedColumnName = "hid", nullable = false, updatable = false, insertable = true)
@OnDelete(action = OnDeleteAction.CASCADE)
private HouseHold houseHold;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "ownerdetails", fetch = FetchType.EAGER)
private List<HouseHoldMembers> membersdetails = new ArrayList<>();
//default constructor
//parameterized constructor
//getter setter
HouseHoldMembers.java
@Entity
@Table(name = "household_members")
public class HouseHoldMembers implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "mem_id_seq")
@SequenceGenerator(name = "mem_id_seq", sequenceName = "mem_id_seq", allocationSize = 1)
@Column(name = "mid")
private Long mid;
@NotNull
@Size(max = 100)
@Column(name = "name")
private String name;
@NotNull
@Size(max = 100)
@Column(name = "education")
private String education;
@NotNull
@Column(name = "age")
private int age;
@NotNull
@Size(max = 10)
@Column(name = "gender")
private String gender;
@NotNull
@Size(max = 100)
@Column(name = "idname")
private String idName;
@NotNull
@Size(max = 100)
@Column(name = "idnumber")
private String idNumber;
@JsonIgnore
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "oid", nullable = false, updatable = false, insertable = true)
@OnDelete(action = OnDeleteAction.CASCADE)
private OwnerDetails ownerdetails;
//default constructor
//parameterized constructor
//getter setter
Dtat.json
{
"district" : "district",
"taluk" : "taluk",
"villageName" : "village name",
"slNo" : 234546674,
"khathaNo" : "35824005",
"localityName" : "localitiyname",
"propertyDetails" : "property Details",
"tenant" : "tenant",
"houseDimension" : "housedimension",
"east":"east",
"west":"west",
"north":"north",
"south":"south",
"rentAmount":2000.45,
"vacantPort":"2342",
"gpId":23112,
"gpName":"gpname",
"propertyType":"proprty type",
"roadName":"road name",
"pin":700003,
"surveyNo":23122,
"gridNo":"23122",
"idNumber":"2321223232232",
"area":"area",
"toiletAvailable":"yes",
"waterFacility":"yes",
"phoneNumber":9999999999,
"housephoto":"",
"mapphoto":"",
"audio":"",
"latitude":"22.453",
"longitude":"88.453",
"surveyorName":"surveyor name",
"serveyStringDate":"2019-10-13 11:25:36",
"totalMembers":"2",
"id":1,
"ownerdetail":
[
{
"name":"name",
"education":"education",
"age":10,
"gender":"male",
"idName":"adhaarcard1",
"idNumber":"23424242343",
"membersdetails":
[
{
"name":"name",
"education":"education",
"age":10,
"gender":"male",
"idName":"adhaarcard2",
"idNumber":"23424242344"
},
{
"name":"name1",
"education":"education1",
"age":11,
"gender":"male",
"idName":"adhaarcard2",
"idNumber":"23424242344"
}
]
}
]
}
Также я создал классы репозитория для каждого класса сущностей. Может кто-нибудь, пожалуйста, помогите мне решить эту ошибку. Заранее спасибо.