MySQL 5.1 + EJB 3.0 + MyEclipse 8.6
EJB逆向工程
1. 点击Window-------->show view-------->other,在弹出的对话框当中,选择MyEclipseDatabase分支下的DB Browser,如下图所示:
2. 最后,点击OK,在工作空间上将会出现一个DB Browser的配置页面,在配置页面空白处,右键,选择New按钮
3. 在弹出的对话框当中配置数据库连接。在配置页面上,选择数据库类型,输入数据库配置名称,输入数据库用户名密码,导入Mysql JDBC Driver即可。
4. 然后选择Next,选择“Display All schemas”。接着,点击Finish按钮,完成了数据库的配置。
5. 最后,使用DB Browser连接到数据库,如下图所示
1. 在DB Browser配置界面,进入hibernate数据库,如下图所示:
2. 点击t_user,在键,选择EJB3 Reverse Engineering,如下图所示:
3. 将弹出如下的对话框,在Java package 当中输入产生的hibernate 映射的JavaBean 为com.ejb.po,详细请参考下图:
4. 点击Next>按钮,在新的对话框当中,选中图示的选框;
5. 点击Next>,可以修改类名或列名;
6. 最后,点击Finish按钮。新的目录结构如下图所示:
生成的Java类:Tbuser.java
package com.ejb.po; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import static javax.persistence.GenerationType.IDENTITY; import javax.persistence.Id; import javax.persistence.Table; /** * Tbuser entity. @author MyEclipse Persistence Tools */ @Entity @Table(name = "tbuser", catalog = "hibernate") public class Tbuser implements java.io.Serializable { // Fields private Integer id; private String name; private String password; private String sex; // Constructors /** default constructor */ public Tbuser() { } /** minimal constructor */ public Tbuser(String name, String password) { this.name = name; this.password = password; } /** full constructor */ public Tbuser(String name, String password, String sex) { this.name = name; this.password = password; this.sex = sex; } // Property accessors @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "id", unique = true, nullable = false) public Integer getId() { return this.id; } public void setId(Integer id) { this.id = id; } @Column(name = "name", nullable = false, length = 20) public String getName() { return this.name; } public void setName(String name) { this.name = name; } @Column(name = "password", nullable = false, length = 11) public String getPassword() { return this.password; } public void setPassword(String password) { this.password = password; } @Column(name = "sex", length = 2) public String getSex() { return this.sex; } public void setSex(String sex) { this.sex = sex; } }
推荐阅读:Hibernate逆向工程示例
@Wentasy 博文仅供参考,欢迎大家来访。如有错误之处,希望批评指正。原创博文如需转载请注明出处,谢谢 :) [CSDN博客] |