Я получаю следующую ошибку при попытке обновить данные в БД с помощью SpringBoot
Ошибка: org.springframework.beans.NotReadablePropertyException: Invalid property 'stateId 'класса EJB [com.studawn.model.District]: не удалось найти поле для свойства во время резервного доступа!
Я не знаю, как это исправить.
Контроллер
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.studawn.exception.StudawnException;
import com.studawn.model.City;
import com.studawn.model.State;
import com.studawn.request.model.DistrictBean;
import com.studawn.request.model.StatePage;
import com.studawn.service.callback.StateCityDistrictService;
import com.studawn.utils.RestUtils;
@CrossOrigin(maxAge = 3600)
@RestController
public class StateCityDistrictController<T> extends RestUtils<T> {
@Autowired
StateCityDistrictService<T> stateCityDistrictService;
@RequestMapping(value = "/updateState", method = RequestMethod.POST, headers = "Accept=application/json")
public @ResponseBody Object updateState(@RequestBody State state) {
try {
return getSuccessResponse(stateCityDistrictService.updateState(state));
} catch (StudawnException e) {
return getErrorResponse(e.getMessage());
}
}
}
Класс обслуживания
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.studawn.combined.repository.CityRepository;
import com.studawn.combined.repository.DistrictRepository;
import com.studawn.combined.repository.StateRepository;
import com.studawn.exception.StudawnException;
import com.studawn.model.AdminUser;
import com.studawn.model.City;
import com.studawn.model.District;
import com.studawn.model.State;
import com.studawn.request.model.DistrictBean;
import com.studawn.request.model.StatePage;
import com.studawn.service.callback.StateCityDistrictService;
import com.studawn.utils.Constant;
import com.studawn.utils.ErrorCode;
@Service
public class StateCityDistrictImpl<T> implements StateCityDistrictService<T>, Constant {
@Autowired
StateRepository stateRepository;
@Autowired
CityRepository cityRepository;
@Autowired
DistrictRepository districtRepository;
@Transactional
@Override
public Object updateDistrict(DistrictBean districtBean) throws StudawnException {
if (districtRepository.isDistrictCodeExists(districtBean.getDistrictCode()) > 0)
throw new StudawnException(ErrorCode.DISTRICT_CODE_ALREADY_EXISTS);
else {
District district = new District();
district.setDistrictId(districtBean.getDistrictId());
district.setDistrictName(districtBean.getDistrictName());
district.setDistrictCode(districtBean.getDistrictCode());
AdminUser adminUser = new AdminUser();
adminUser.setLogInId(districtBean.getLastUpdatedBy());
district.setLastUpdatedBy(adminUser);
State state = new State();
state.setStateId(districtBean.getStateId());
district.setState(state);
return stateRepository.saveAndFlush(district);
}
}
}
Районный орган
@Entity
@Table(name = "district")
public class District {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "district_id")
private int districtId;
@Column(name = "district_name", length = 45)
private String districtName;
@Column(name = "district_code", length = 45)
private String districtCode;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created_date", nullable = false, updatable = false)
@CreatedDate
private Date dateCreated;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "modified_date")
@LastModifiedDate
private Date dateModified;
@JsonBackReference(value = "createdBy")
@ManyToOne
@JoinColumn(name = "created_by", updatable = false, nullable = false)
private AdminUser createdBy;
@JsonBackReference(value = "lastUpdatedBy")
@ManyToOne
@JoinColumn(name = "last_updated_by")
private AdminUser lastUpdatedBy;
@JsonIgnore
@OneToMany(mappedBy = "district", fetch = FetchType.LAZY)
private Set<City> cityList;
@JsonBackReference(value = "stateId")
@ManyToOne
@JoinColumn(name = "state_id")
private State state;
@JsonIgnore
@OneToMany(mappedBy = "district")
private Set<Pincode> pincode;
@JsonIgnore
@OneToMany(mappedBy = "district")
private List<College> college;
@JsonIgnore
public Set<City> getCity() {
return cityList;
}
public void setCity(Set<City> cityList) {
this.cityList = cityList;
}
public String getDistrictCode() {
return districtCode;
}
public void setDistrictCode(String districtCode) {
this.districtCode = districtCode;
}
public List<College> getCollege() {
return college;
}
public void setCollege(List<College> college) {
this.college = college;
}
public Set<Pincode> getPincode() {
return pincode;
}
public void setPincode(Set<Pincode> pincode) {
this.pincode = pincode;
}
public int getDistrictId() {
return districtId;
}
public void setDistrictId(int districtId) {
this.districtId = districtId;
}
public String getDistrictName() {
return districtName;
}
public void setDistrictName(String districtName) {
this.districtName = districtName;
}
public Date getDateCreated() {
return dateCreated;
}
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
public Date getDateModified() {
return dateModified;
}
public void setDateModified(Date dateModified) {
this.dateModified = dateModified;
}
public AdminUser getCreatedBy() {
return createdBy;
}
public void setCreatedBy(AdminUser createdBy) {
this.createdBy = createdBy;
}
public AdminUser getLastUpdatedBy() {
return lastUpdatedBy;
}
public void setLastUpdatedBy(AdminUser lastUpdatedBy) {
this.lastUpdatedBy = lastUpdatedBy;
}
public Set<City> getCityList() {
return cityList;
}
public void setCityList(Set<City> cityList) {
this.cityList = cityList;
}
public State getState() {
return state;
}
public void setState(State state) {
this.state = state;
}
}
Государственный субъект
@Entity
@Table(name = "state")
public class State {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "state_id")
private int stateId;
@Column(name = "state_name", length = 45)
private String stateName;
@Column(name = "state_code", length = 45)
private String stateCode;
@JsonIgnore
@OneToMany(mappedBy = "state", fetch = FetchType.LAZY)
private Set<City> cityList;
@JsonIgnore
@OneToMany(mappedBy = "state", fetch = FetchType.LAZY)
private Set<District> districtList;
@JsonIgnore
@OneToMany(mappedBy = "state")
private List<College> college;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created_date", nullable = false, updatable = false)
@CreatedDate
private Date dateCreated;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "modified_date")
@LastModifiedDate
private Date dateModified;
@JsonBackReference(value = "createdBy")
@ManyToOne
@JoinColumn(name = "created_by", updatable = false, nullable = false)
private AdminUser createdBy;
@JsonBackReference(value = "lastUpdatedBy")
@ManyToOne
@JoinColumn(name = "last_updated_by")
private AdminUser lastUpdatedBy;
public String getStateCode() {
return stateCode;
}
public void setStateCode(String stateCode) {
this.stateCode = stateCode;
}
public Date getDateCreated() {
return dateCreated;
}
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
public Date getDateModified() {
return dateModified;
}
public void setDateModified(Date dateModified) {
this.dateModified = dateModified;
}
public AdminUser getCreatedBy() {
return createdBy;
}
public void setCreatedBy(AdminUser createdBy) {
this.createdBy = createdBy;
}
public AdminUser getLastUpdatedBy() {
return lastUpdatedBy;
}
public void setLastUpdatedBy(AdminUser lastUpdatedBy) {
this.lastUpdatedBy = lastUpdatedBy;
}
public List<College> getCollege() {
return college;
}
public void setCollege(List<College> college) {
this.college = college;
}
public int getStateId() {
return stateId;
}
public void setStateId(int stateId) {
this.stateId = stateId;
}
public String getStateName() {
return stateName;
}
public void setStateName(String stateName) {
this.stateName = stateName;
}
public void setCityList(Set<City> cityList) {
this.cityList = cityList;
}
public Set<City> getCityList() {
return cityList;
}
public void setDistrictList(Set<District> districtList) {
this.districtList = districtList;
}
public Set<District> getDistrictList() {
return districtList;
}
}
District Bean
public class DistrictBean {
private int districtId;
private String districtName;
private String districtCode;
private String createdBy;
private String lastUpdatedBy;
private int stateId;
public String getDistrictCode() {
return districtCode;
}
public void setDistrictCode(String districtCode) {
this.districtCode = districtCode;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public String getLastUpdatedBy() {
return lastUpdatedBy;
}
public void setLastUpdatedBy(String lastUpdatedBy) {
this.lastUpdatedBy = lastUpdatedBy;
}
public int getStateId() {
return stateId;
}
public void setStateId(int stateId) {
this.stateId = stateId;
}
public int getDistrictId() {
return districtId;
}
public void setDistrictId(int districtId) {
this.districtId = districtId;
}
public String getDistrictName() {
return districtName;
}
public void setDistrictName(String districtName) {
this.districtName = districtName;
}
}
JSON Request
{
"districtId":1,
"districtCode":"Chn" ,
"districtName":"Chennai",
"lastUpdatedBy":"arun@xyz.com",
"stateId":1
}
Заранее спасибо!