, first, after the project has been built into two types of jar package, a kind of hibernate jar package, a kind of JDBC jar package
Second, click "Window"--"show View"--"other"-"Hibernate configurations"
Third, add the configuration. Right-click in the Hibernate Configurations window and select Add Configuration. Configures information about the database link in the window.
They'll come out when they're configured. hibernate.cfg.xml file
Iv. generating classes and configuration files for each table
Click "Run"--"Hibernate code Generation ..."--"Hibernate code Generation Configuration"
After clicking Run, it will automatically generate
As shown in the basic configuration is completed, but also to the hibernate.cfg.xml file to configure each of the mappings
<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE hibernate-configuration Public "-//hibernate/hibernate configuration DTD 3.0//en" "Http://www.hi Bernate.org/dtd/hibernate-configuration-3.0.dtd "><hibernate-configuration> <session-factory> < Propertyname= "Hibernate.connection.driver_class">Com.mysql.jdbc.Driver</ Property> < Propertyname= "Hibernate.connection.url">Jdbc:mysql://127.0.0.1:3306/mydb</ Property> < Propertyname= "Hibernate.connection.username">Root</ Property> < Propertyname= "Hibernate.default_catalog">MyDB</ Property> < Propertyname= "Hibernate.dialect">Org.hibernate.dialect.MySQLDialect</ Property> < Propertyname= "Show_sql">Ture</ Property> <!--table mappings for each - <MappingResource= "Com/itnba/maya/model/family.hbm.xml"/> <MappingResource= "Com/itnba/maya/model/info.hbm.xml"/> <MappingResource= "Com/itnba/maya/model/nation.hbm.xml"/> <MappingResource= "Com/itnba/maya/model/title.hbm.xml"/> <MappingResource= "Com/itnba/maya/model/work.hbm.xml"/> </session-factory></hibernate-configuration>
Test
PackageCom.itnba.maya.model;Importjava.util.ArrayList;Importjava.util.List;ImportOrg.hibernate.*;Importorg.junit.Test;Importjunit.framework.TestCase; Public classAextendsTestCase {@Test Public voidTesta () {Session session=NULL; Try{Session=hibernateutil.getsession (); Info Info=session.get (Info.class, "P003"); System.out.println (Info.getname ()+info.getnation (). GetName ()); }Catch(Exception e) {e.printstacktrace (); }finally{hibernateutil.closesession (); } }}
Run results, no problem
Quickly create hibernate frames with tools