Hibernate learning Notes (1)-----------Jar Package Introduction and Getting Started

Source: Internet
Author: User

Currently in learning Hibernate

Suddenly found that hibernate jar package, when introduced, very cumbersome, and even if there is no introduction will have problems, so

Self-organized a bit, the introduction of the jar package to sort out, so that later will forget, in order to hope to help everyone!

First download the Hibernate jar Package

http://download.csdn.net/detail/u011225629/8697639

Open lib file in file hibernate-distribution-3.6.10.final

1. There is a require folder the jar under this folder must all be introduced

2. There is a jar under the Hibernate-jpa-api-jar folder called the JPA folder that needs to be introduced

3. Thehibernate-distribution-3.6.10.final folder has two jar packages, respectively Hibernate2.jar, Hibernate-logo.jar,

Hibernate-test.jar need to introduce

4. Join the MySQL connection jar you should know which jar it is.

The above jar packages are required to be introduced!!!! Indispensable!

Second, the jar of other files under the Lib folder is introduced according to different requirements!

Documention files for learning APIs as well as PDF

Project files are some project and hibernate core code

The following is the actual introduction of the JAR package!

Click on the project right click on properties in the left navigation click Java Build Path

In the upper navigation bar there is a libary click on the middle of the panel will appear some you do not have the eclipse in the Jar package library, click on the right side of the button add Libary

Another box appears click User libary

Click on the Next button below to appear

Here's the value of the Custom Jar package Library

Here we are using User libary, which is to put our jar package into our myeclipse and not add to our project

In this way, we can directly refer to the jar we define in the future when we build the project

Take our hibernate, I bring all the Hibernate jar packages into my own jar Libaryjar Package Library

When we are building an additional hibernate project, we can directly use the jar library without having to bother with the introduction of the jar for a time-consuming effort, as well as the possibility of missing jars.

Want to be good at their work, its prerequisite.

Click New to create a new user libary, fill in your own defined Jar package library

Here I define a user's Jar package library Click on the right of the add jars ... Add the required jar package to the inside

Once you have added the jar packages you need, click OK

This is where you have completed your own definition of the JAR package library

How to introduce your jar package libraries:

Click on the project right-click Build libary path click on User libary--"next

Select the jar package you want to introduce! Click Finish

Done!!!

Here's an introductory case for hibernate!

Client.java

Package Com.haixu.hibernate;import Org.hibernate.session;import Org.hibernate.sessionfactory;import Org.hibernate.transaction;import Org.hibernate.cfg.configuration;public class Client {@SuppressWarnings ("null") public static void Main (string[] args) {Configuration cfg = null; Sessionfactory SF = null; Session session = NULL; Transaction tx = NULL; User User1 = new user ();    User1.setusername ("Haixu");    User1.setpassword ("Haixu");    User1.setage (a);        try {    cfg = new Configuration (). Configure (); SF = Cfg.buildsessionfactory (); session = Sf.opensession (); tx = Session.begintransaction (); Session.save (user1); Tx.commit ();} catch (Exception e) {//Todo:handle exceptione.printstacktrace (); if (tx==null) {tx.rollback ();}} Finally{sf.close (); Session.close ();}}    }


User.java

Package Com.haixu.hibernate;public class User {private int id;private string username;private string password;private int age;public int getId () {return ID;} public void setId (int id) {this.id = ID;} Public String GetUserName () {return username;} public void Setusername (String username) {this.username = username;} Public String GetPassword () {return password;} public void SetPassword (String password) {this.password = password;} public int getage () {return age;} public void Setage (int.) {this.age = age;}}


User.hbm.xml

<! DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "http://www.hibernate.org/dtd/ Hibernate-mapping-3.0.dtd ">


Hibernate.cfg.xml

<! DOCTYPE hibernate-configuration Public "-//hibernate/hibernate configuration DTD 3.0//en" "http://www.hibernate.org/ Dtd/hibernate-configuration-3.0.dtd ">


Operation Result:

Hibernate:     Select        max (ID)     from        userhibernate:     insert     into        user        (username, Password, age, id)     values        (?,?,?,?)


Done!


Hibernate learning Notes (1)-----------Jar Package Introduction and Getting Started

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.