私はSpring MVCとHibernateで新しく、問題が発生しました。 Userテーブル(Many to One)に接続されているHibernateで作成したChildテーブルがあります。 Hibernateが子テーブルを作成するとき、これら2つのテーブルが接続されている 'user_object'(タイプUser)によって自動的に 'user_object_id'が追加されます。しかし、私は問題があるだけで彼の子供のユーザーに表示したいとき:HTTPステータス500 - 要求処理に失敗しました。入れ子になった例外はorg.hibernate.QueryException:プロパティを解決できませんでした
HTTP Status 500 - Request processing failed; nested exception is org.hibernate.QueryException:
could not resolve property: user_object_id of: com.websystique.springmvc.model.Child
私はfindAllUserChilds方法でChildDaoImplクラスのテーブルから子オブジェクトを取得し、その後ChildControllerでChildDTO(POJOオブジェクト)にマップします。この変数はHibernateによって自動的に作成され、CriteriaによってfindAllUserChilds()に返されるため、この変数はそこに存在しないため、エラーは子モデルの 'user_object_id'と接続されています。どうすればこの問題を解決できますか?
子供:
@Entity
@Table(name= "Child")
public class Child implements Serializable
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column (nullable=false)
private String first_name;
@Column (nullable=false)
private String last_name;
@Column (nullable=false)
private String birth_city;
@Column (nullable=false)
private String pesel;
@Column (nullable=false)
private String sex;
@Column (nullable=false)
private String blood_group;
@Column (nullable=false)
private String birth_date;
@ManyToOne
private User user_object;
public User getUser_object() {
return user_object;
}
public void setUser_object(User user_object) {
this.user_object = user_object;
}
(...
some getters and setters
...)
}
ChildController:
@RequestMapping(value = "/mainpanel" , method = RequestMethod.GET,
headers = "accept=application/json")
public List<ChildDTO> listChild(HttpServletResponse request)
{
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String username = auth.getName();
User user = userService.findUserByUsername(username);
List<Child> list = service.findAllUserChilds(user.getId());
List<ChildDTO> result = new ArrayList<>();
for (Child child : list)
{
result.add(ChildMapper.map(child));
}
return result;
}
ChildDaoImpl:
@Repository("ChildDao")
public class ChildDaoImpl extends AbstractDao<Integer, Child> implements ChildDao {
@SuppressWarnings("unchecked")
public List<Child> findAllUserChilds(int user_id)
{
Criteria criteria = createEntityCriteria();
criteria.add(Restrictions.eq("user_object_id", user_id));
return (List<Child>) criteria.list();
}
}