標籤:style blog http io color ar os sp java
假定你的jdk,eclipse都已安裝好
1、選擇eclipse -->helper-->eclipse makerplace
2、在快顯視窗中的find中輸入hibernate 點擊搜尋 選擇hibernate tools(indlgo)3.4x 點擊install (因為我這裡安裝過所以會顯示update、uninstall)
3、點擊install會提示是否同意,選擇同意進行安裝
4、安裝了怎麼沒有變化呢難道哪裡出問題了,不要著急現在我們調出hibernate視窗
依次選擇eclipse-->windows-->openperspective 在彈出的視窗中選擇hibernate
預設會在下方顯示,就是顯示日誌並列的視窗
5、添加設定檔 調出hibernater視窗之後點擊+號按鈕 會調出如何視窗
對對,就是那個紅圈
project 選擇當前項目, database connection 就選擇圖上的,然後點擊configuration file左邊的按鈕 setup 然後會彈出如下視窗
這裡說白了就是讓你配置資料連線的,按配置空的可以不用寫。然後點擊完成項目目錄下面會多出一個*.cfg.xml檔案就是儲存這些資訊的
6、接著往下走按圖選擇
點擊hibernate code generation....彈出如下
console configuration 選擇我們上面建立的那個配置,output dirctory 輸出直接選取當前項目下的檔案夾,主要是reveng.xml 點擊後面的setup
點擊setup之後會彈出上面視窗這裡主要配置我的產生orm的表,圖中1、選擇我的建立的配置項,2、選擇要產生的表,3、inlucde 增加表,選擇後後單擊下面的完成
7、開始調用
Configuration cfg = new Configuration().configure() ; SessionFactory sFactory = cfg.buildSessionFactory() ; Session session = sFactory.openSession() ;Transaction tx = session.beginTransaction();Com.Tt user=new Com.Tt();user.setId(5);user.setUsername("444"); session.save(user); Query ql=session.createQuery("from Tt"); java.util.List result=ql.list(); tx.commit();session.close();
咋不對呢,怎麼會報錯???、有木有 就在這裡“Configuration cfg = new Configuration().configure() ; ”
別著急是因為我們少引用相關的jar了,找到你eclipse所在的目錄-->plugins->org.hibernate.eclipse.libs_XXXXX檔案夾,本人是將這裡的所有jar都引用了省的老是報錯。
再執行,ok 了
linux eclipse hibernate 配置