在hibernate4之后就移除了AnnotationConfiguration()方法了,Configuration已經包含了注解的方法,所以你可以直接用:
Configuration con = new Configuration(); SessionFactory sf = con.configure().buildSessionFactory(); Session s = sf.openSession();
來獲得用注解聲明映射關系的Session了,加上配置:
<mapping class="student.Teacher"/>
就OK了,方便了很多。
但在配置過程中我還報了一個錯誤:
No identifier specified for entity: student.Teacher
這是因為我把主鍵id的注解加在了setId上,把他加在getId上就解決了。(真是粗心)
