Hibernate xml设置映射问题

时间:2017-11-15 19:51:59

标签: java mysql hibernate

我刚刚学习了Hibernate,并且在xml mapping方面遇到了一些问题。错误代码:

 public void changeFragment(final Fragment fragment, final String fragmenttag) {

    try {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                FragmentManager fragmentManager = getSupportFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction().addToBackStack(null);
                fragmentTransaction.replace(R.id.fram, fragment, fragmenttag);
                fragmentTransaction.commit();
                fragmentTransaction.addToBackStack(null);
            }
        }, 50);
    } catch (Exception e) {

    }

}

我要映射的数据库的一部分看起来像这样 part of db

在java应用程序中,我有两个实体类,用于每个表。我不在这里插入getter setter和constructor以提高可读性。

Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute statement

Xml映射看起来像这样。

 public class OccupiedBedsEntity {
    private int id;
    private Timestamp since;
    private Timestamp to;
    private int id_room;
}




  public class RoomEntity {
        private int id;
        private int roomNumber;
        private Integer numberOfBeds;
        private int id_department;
        private int idResponsibleDoctor;
        private Set beds;
    }

也许我必须改变不是在xml中的东西,而是在java类中?

1 个答案:

答案 0 :(得分:0)

错误是在OccupiesBebsEntity xml mapper中的这一行。

<class name="entity.OccupiedBedsEntity" table="occupied_beds" schema="medicine" catalog="medicine">

代码应如下所示。

<class name="entity.OccupiedBedsEntity" table="occupied_beds" schema="" catalog="medicine">