Java Framework: Hibernate

Source: Internet
Author: User

One: Introduction

Hibernate is the DAO layer in Java, which deals with persistent layers. The underlying is also database driven, connected, and so on. He also has an ORM, class, and database mapping.

II. deployment

: Https://sourceforge.net/projects/hibernate/?source=typ_redirect

1) Package Description:

2:) CREATE Database

1 CREATE TABLE customer (ID BIGINT not NULL auto_increment primary key,name varchar), Ipone_number var char (+));

3) Create Hibernate profile

1) JavaBean File

1 Package Jd.com.hibernatepro;2 3  Public classCustomer {4      PublicCustomer () {};5     PrivateLong ID;6     PrivateString name;7     PrivateString Ipone_number;8 9      Public voidsetId (Long id) {Ten          This. ID =ID; One     } A  -      Public voidSetipone_number (String ipone_number) { -          This. Ipone_number =Ipone_number; the     } -  -      Public voidsetName (String name) { -          This. Name =name; +     } -  +      PublicLong getId () { A         returnID; at     } -  -      PublicString Getipone_number () { -         returnIpone_number; -     } -  in      PublicString GetName () { -         returnname; to     } +}

2) Create a mapping file (Customer.hbm.xml)

The name is not mandatory, but it is usually the class name. HBM (Hibernate mapping). xml

Configuration file Contents:

1<?xml version="1.0"encoding="UTF-8"Standalone="No"?>2<! DOCTYPE hibernate-Mapping Public3         "-//hibernate/hibernate Mapping DTD 3.0//en"4         "HTTP://WWW.HIBERNATE.ORG/DTD/HIBERNATE-MAPPING-3.0.DTD">56<!--configuration classes and table structure mappings--7<className="Jd.com.hibernatepro.Customer"table="Customer">8<!--configuration ID name is the JavaBean property column is the property property of the table, you can omit column--9<id name="ID"column="ID">Ten<!--primary key generation policy native the local policy increment policy taken by the primary key-- One<!--Note that syntax XML is not <generator></generator--> A<generatorclass="native"/> -</id> -<!--Configure additional properties-- the<property name="name"/> -<property name="Ipone_number"/> -</class> -  +

where constraints:

Copy from Web-inf/lib/hibernate-core-5.0.7.final.jar

which

1 is a constraint lookup file for Hibernate's core configuration file.

2 is the constraint lookup file for the mapping configuration file.

Our side chooses 3.0.

3) Create core profile: File name must be hibernate.cfg

The constraint copy is as above.

Content:

1<?xml version="1.0"encoding="UTF-8"Standalone="No"?>2<! DOCTYPE hibernate-Configuration Public3         "-//hibernate/hibernate Configuration DTD 3.0//en"4         "HTTP://WWW.HIBERNATE.ORG/DTD/HIBERNATE-CONFIGURATION-3.0.DTD">5<!--Remember to configure Session-factory label a database for one session-factory label--67<session-factory>8<!--the parameters that must be configured are 5 4 are connected to the database string one is the database dialect---9<property name="Hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>Ten<property name="Hibernate.connection.url">jdbc:mysql:///Test</property> One<property name="Hibernate.connection.username">root</property> A<!--dialect tells Hibernate to use that database type-- -<property name="Hibernate.connection.password">123456</property> -<property name="Hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> the</session-factory> -

Hibernate configuration is finished.

Java Framework: Hibernate

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.