资源描述:
《hibernate正向工程和逆向工程》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、一、正向工程MyEclipse使用hibernate正向工程,hibernate的正向工程是指从java实体类生成数据库表的过程,这种过程符合java程序员面向对象编程的思想,也是工程设计的时候使用比较多的一种思想。具体实施过程如下。①手动创建POJO类,并对POJO类加上Hibernate注解(hibernateannotation)。这样做的目的是通过MyEclipse来生成hibernate映射文件,POJO类如下(省略set方法):②配置MyEclipsexdoclet:具体配置方法为,项目选中右击点properties如下图操作:locatedintheTomb,DongSh
2、enJiabang,deferthenextdayfocusedontheassassination.Linping,Zhejiang,1ofwhichliquorwinemasters(WuzhensaidinformationisCarpenter),whogotAfewbayonets,duetomissedfatal,whennightcame③选中当前项目名称右击MyEclipse点击RunXDoclet:④生成的映射文件:locatedintheTomb,DongShenJiabang,deferthenextdayfocusedontheassassination.Lin
3、ping,Zhejiang,1ofwhichliquorwinemasters(WuzhensaidinformationisCarpenter),whogotAfewbayonets,duetomissedfatal,whennightcame二,逆向工程由数据库表生成javapojo和hibernate映射文件①创建数据库数据表:②配置数据库:点击Window-->showview-->other,选择MyEclipseEnterpriseWorkBench分支下的DBBrowser,如下图所示:在DBBrowser窗口中右键单击空白处选择“New”...,弹出如下窗口进行数据库配
4、置(和hibernate.cfg.xml)一样:配置完成之后出现如下连接:locatedintheTomb,DongShenJiabang,deferthenextdayfocusedontheassassination.Linping,Zhejiang,1ofwhichliquorwinemasters(WuzhensaidinformationisCarpenter),whogotAfewbayonets,duetomissedfatal,whennightcame④创建项目,添加Hibernate支持(略)⑤通过反向工程,生成POJO及hbm映射文件:在DBBrowser配置界面
5、,找到test数据库,展开到表,如下图所示:选中tb_user点击右键,选择HibernateReverseEngineering,如下图所示:将弹出如下的对话框:locatedintheTomb,DongShenJiabang,deferthenextdayfocusedontheassassination.Linping,Zhejiang,1ofwhichliquorwinemasters(WuzhensaidinformationisCarpenter),whogotAfewbayonets,duetomissedfatal,whennightcame点击Next>按钮,在新的对
6、话框当中,在IDGenerator的选项当中选择increment,表示ID为数据库自增长:点击Next>,可以修改类名或列名:最后,点击Finish按钮,新的目录结构如下图所示:locatedintheTomb,DongShenJiabang,deferthenextdayfocusedontheassassination.Linping,Zhejiang,1ofwhichliquorwinemasters(WuzhensaidinformationisCarpenter),whogotAfewbayonets,duetomissedfatal,whennightcame