使用資源映射
由於您使用的是測繪資源,問題是在你的emp.hbm.xml
提到的類路徑,因爲你Employee.java
包hibernatetutorial1
類路徑將是hibernatetutorial1.Employee
內。所以,你需要在你的emp.hbm.xml
//emp.hbm.xml
<hibernate-mapping>
<class name="hibernatetutorial1.Employee" table="tablename">
.......
.......
</hibernate-mapping>
更何況這和地圖內Hibernate.cfg.xml
//Hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
......
......
......
<mapping resource="emp.hbm.xml"/>
</session-factory>
</hibernate-configuration>
這種資源使用註解類映射
這是更好地使用註釋類,因爲它們減少你的負擔,如果您使用帶註釋的類,那麼您需要在Hibernate.cfg.xml
中提及您的類路徑,並且您需要使用映射類,不需要映射reso urce
//using annotated class mapping no need of emp.hbm.xml(resource mapping)
//Hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
......
......
......
<mapping class="hibernatetutorial1.Employee"/>
</session-factory>
</hibernate-configuration>
*產生的原因:拋出java.lang.ClassNotFoundException * –
能否請你告訴我你的Employee類和你是如何創建Hibernate的Session堅持Employee對象? –