Use the MiddleGenIDE tool to generate the POJO of hibernate (generate the POJO class according to the data table)

Recommendation: MiddlegenIDE plug-in, is an Eclipse plug-in. 
    It can be used to connect directly to the database, according to the table according to certain HIBERNATE rules to make BEAN and corresponding XML, after use, you can manually delete it loaded JAR package and XML file! 

    Start today I tried to use the MiddleGenIDE tool, which is really convenient and saves a lot of time. Its installation method is to download a middlegenide_1.3.3.zip file, then extract it to the root directory of eclipse, and extract it into dropins. Restart eclipse again and you can use it. The installation is very convenient, and then create a MiddleGenIDETest project. Right-click on the project-New-other to find middlegen, select the default file name, click Next, and fill in the JDBC jar, URI, USER, PASSWORD, etc., then click Load Table, press the shift key to select all, fill in the package name com.demo.hibernate.beans, select hibernate for the export file, click finish, the export window will pop up, click each table separately, click the Generate button, and then The closing is completed, and the .hbm.xml file for each table is generated. 

Download: 
middlegenide_1.3.3.zip  (7.7 MB)  http://sourceforge.net/projects/middlegen/files/

Using  MiddlegenIDE

A friend recently sent a letter saying that something was wrong with MiddlegenIDE's homepage, and the content displayed on the login was inexplicable. Makes it difficult for novices to use MiddlegenIDE. I took a look at this seat, and it is really inexplicable. Let's summarize a tutorial on using MiddlegenIDE. 

MiddleGen for Hibernate plus the Hibernate_Extension toolkit is actually used to facilitate us to export the table structure from the existing database and generate the corresponding hbm, cfg files and POJO class code. MiddleGenIDE is MiddleGen's Eclipse plug-in. The whole set has not been updated for a long time. Therefore, although the eclipse version 3.1.x currently used by this seat can also work with this plug-in normally, it does not provide the function of online update. You need to download middlegenide first , install the plugin and restart Eclipse. If the newly opened eclipse does not change, it is estimated that you have to restart it with the "-clean" parameter, or delete the corresponding file under the configuration folder. 

OK, let's talk about how to use it. First of all, of course, we need to build an environment (I have updated MySQL to 5.0 now, and Hibernate is 2.1 as it was then), and then we build a table and load some data. The script to create a table under MySQL is as follows: 

DROP TABLE IF EXISTS `test`.`t_user`;
CREATE TABLE  `test`.`t_user` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) default NULL,
PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;

With the table, create a Java project. Then right-click on the Src folder and select "New-Other"

Then the option for Middelgen Bird File will pop up. Because MiddleGen is a package that uses Ant to compile files to call up the IDE, this plugin is actually just for us to write this Build File in a cloze method.

After clicking, the following interface will appear, the corresponding content is clear at a glance, and you can fill in according to your needs.

The picture below is what it looks like after filling it out. Friends who do not use Hibernate 3 like this seat, pay attention to lowering the version of hibernate in the option option circled in red. Otherwise, the configuration file produced will have a very strange "xml parser cannot parse dtd" error.

After filling in all the things, click Next to enter the MiddleGen interface. You can get the configuration file and POJO class by clicking Generate directly without changing anything.

In addition, if you need the POJO generated in MiddleGen directly marked with Xdoclet, you need to find its own template file: 
1            
eclipse\plugins\org.ultimania.middlegenide_1.3.2\resource\template\build-hibernate.xml .vm

Then change the value of the following line to generate the xdoclet tag to true: 1            
<property name="gen.xdoclet-tag" value="true">

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326988160&siteId=291194637