Quickly create hibernate frames with tools

Source: Internet
Author: User

, 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.