使用myeclipse-2013-sr2進行hibernate的快速開發

一、新建一個Java Project

二、通過myeclipse提供的數據庫瀏覽器連接到mysql數據庫。

1、單擊 菜單"window"---"open perspective"---MyEclipse database Explorer。

2、在DB Browser窗口將原有的刪掉,右鍵---"new",出現Database Driver配置界面(如下圖),並在界面中進行相應配置,並可進行Test Driver,

看是否能測試成功。



3、在myMysql上右鍵---"Open Connection"。在myMysql中找到自己原先建好的test數據庫和Employee表(見下圖)。


建表語句:

use test;
create table employee
(
	id int not null auto_increment,
	name varchar(10),
	email varchar(20),
	primary key(id)
)charset=utd8;

4、引入hibernate開發包

先切換會Java視圖,在已經建好的hibernate2-4工程上  右鍵---"MyEclispe"---"Project   Facets"---"Install  Hibernate  Facet"。彈出如下界面:


在該界面中選擇Hibernate版本及運行環境。然後next,出現如下界面:


按上圖選擇後,next,出現如下界面,並按圖配置:


然後finish即可。

5、使用myeclipse逆向工程,自動創建數據庫中employee表所對應的domain類。

在DB Browser中的myMysql  employee表上 右鍵---"Hibernate  Reverse  Engineering",出現下圖,並按圖配置。


next,在該界面選擇id Generator的方式。然後finish就可以了。








發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章