HTTP状态500 - 内部服务器从数据库中收集数据时出错。查询在控制台中工作正常,但是restclient给出了错误。这是我的代码。
@Entity
@Table(name = "Patient")
public class Patient {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private int patientId;
private String firstName;
private String lastName;
private int age;
private String cnic;
private String contactNumber;
private String homeNumber;
private String country;
private String city;
private String town;
private String streetNo;
private String houseNo;
private String email;
private String username;
private String password;
@OneToMany(cascade=CascadeType.ALL, mappedBy="patient", fetch=FetchType.EAGER)
private Collection<Vitals> vitals = new ArrayList<Vitals>();
public int getPatientId() {
return patientId;
}
public void setPatientId(int patientId) {
this.patientId = patientId;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getCnic() {
return cnic;
}
public void setCnic(String cnic) {
this.cnic = cnic;
}
public String getContactNumber() {
return contactNumber;
}
public void setContactNumber(String contactNumber) {
this.contactNumber = contactNumber;
}
public String getHomeNumber() {
return homeNumber;
}
public void setHomeNumber(String homeNumber) {
this.homeNumber = homeNumber;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getTown() {
return town;
}
public void setTown(String town) {
this.town = town;
}
public String getStreetNo() {
return streetNo;
}
public void setStreetNo(String streetNo) {
this.streetNo = streetNo;
}
public String getHouseNo() {
return houseNo;
}
public void setHouseNo(String houseNo) {
this.houseNo = houseNo;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getId(){
return patientId;
}
public Patient getPatient(){
return this;
}
public Collection<Vitals> getVitals() {
return vitals;
}
public void setVitals(Collection<Vitals> vitals) {
this.vitals = vitals;
}
}
从数据库获取数据的服务类方法:
@SuppressWarnings("unchecked")
public ArrayList<Patient> getAllPatients(){
ArrayList<Patient> retPatient = new ArrayList<Patient>();
try{
sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
retPatient = (ArrayList<Patient>) session.createCriteria(Patient.class).list();
session.close();
}catch(Exception ex){
ex.printStackTrace();
}
return retPatient;
}
控制台输出:
Hibernate: select this_.patientId as patientId5_1_, this_.age as age5_1_, this_.city as city5_1_, this_.cnic as cnic5_1_, this_.contactNumber as contactN5_5_1_, this_.country as country5_1_, this_.email as email5_1_, this_.firstName as firstName5_1_, this_.homeNumber as homeNumber5_1_, this_.houseNo as houseNo5_1_, this_.lastName as lastName5_1_, this_.password as password5_1_, this_.streetNo as streetNo5_1_, this_.town as town5_1_, this_.username as username5_1_, vitals2_.patient_patientId as patient8_5_3_, vitals2_.vitalId as vitalId3_, vitals2_.vitalId as vitalId7_0_, vitals2_.bpHigh as bpHigh7_0_, vitals2_.bpLow as bpLow7_0_, vitals2_.heartBeat as heartBeat7_0_, vitals2_.patient_patientId as patient8_7_0_, vitals2_.respiratoryRate as respirat5_7_0_, vitals2_.suger as suger7_0_, vitals2_.temperature as temperat7_7_0_ from Patient this_ left outer join Vitals vitals2_ on this_.patientId=vitals2_.patient_patientId
有谁能告诉我,我在这里做错了什么。我将感恩:)