Reverse Engineering Using Hibernate
Hello Friends.today i am going to demonstrate how you can reverse engineer process of creating entities in eclipse using hibernate tools(originally JBoss tools).well you need to go through hibernate site to know about hibernate.revnge.xml ,well its not all about code .so i am putting snapshot of steps that you need to follow as per given below:
1)open hibernate perspective from from window->perspective & from then select hiebernate
(2)here i am demostrating example of sample database.
in Hibernate Perspective, right click and select “Add Configuration…”
In “Edit Configuration” dialog box,
(3) List of tables is shown :
(4) Now, you are ready to generate the Hibernate mapping files and annotation codes.
go to run->Hibernate Code Generation ,select Hibernate Code Generation Configuration
Create a new configuration, select your “console configuration”, puts your “Output directory” and checked option “Reverse engineer from JDBC Connection“.
In “Exporter” tab, select what you want to generate, Model , mapping file (hbm) , DAO, annotation code and etc.
(5) you can see using single reverse engineer file ,hibernate tools provide you easy way to get entity classes generated automatically.it reduces amount of work required to write entity classes by own.
hibernate.reveng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<!-- sample is the name of database and student is the entity within sample database-->
<table-filter match-catalog="sample" match-name="student"/>
</hibernate-reverse-engineering>
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="MySessionFactory">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">admin!@#</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sample</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
</session-factory>
</hibernate-configuration>
the project structure will look like given below:
this is how you can apply reverse engineering process to get entity classes generated by hibernate itself
thanks for reading
for any query ping me on pathak.nisarg@yahoo.com
Regards
Hello Friends.today i am going to demonstrate how you can reverse engineer process of creating entities in eclipse using hibernate tools(originally JBoss tools).well you need to go through hibernate site to know about hibernate.revnge.xml ,well its not all about code .so i am putting snapshot of steps that you need to follow as per given below:
1)open hibernate perspective from from window->perspective & from then select hiebernate
(2)here i am demostrating example of sample database.
in Hibernate Perspective, right click and select “Add Configuration…”
In “Edit Configuration” dialog box,
- In “Project” box, click on the “Browse..” button to select your project.
- In “Database Connection” box, click “New..” button to create your database settings.
- In “Configuration File” box, click “Setup” button to create a new or use existing “Hibernate configuration file”,
hibernate.cfg.xml
(3) List of tables is shown :
(4) Now, you are ready to generate the Hibernate mapping files and annotation codes.
go to run->Hibernate Code Generation ,select Hibernate Code Generation Configuration
Create a new configuration, select your “console configuration”, puts your “Output directory” and checked option “Reverse engineer from JDBC Connection“.
In “Exporter” tab, select what you want to generate, Model , mapping file (hbm) , DAO, annotation code and etc.
(5) you can see using single reverse engineer file ,hibernate tools provide you easy way to get entity classes generated automatically.it reduces amount of work required to write entity classes by own.
hibernate.reveng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<!-- sample is the name of database and student is the entity within sample database-->
<table-filter match-catalog="sample" match-name="student"/>
</hibernate-reverse-engineering>
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="MySessionFactory">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">admin!@#</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sample</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
</session-factory>
</hibernate-configuration>
the project structure will look like given below:
this is how you can apply reverse engineering process to get entity classes generated by hibernate itself
thanks for reading
for any query ping me on pathak.nisarg@yahoo.com
Regards
awesome post.keep sharingvisit us
ReplyDeleteHey thomas.sure.thank you...
ReplyDelete