Configuration method based on Hibernate Framework under eclipse (must see)
1、 ORM
O: Object object
R: Realtion (relational database)
M: Mapping mapping
ORM: Object Relational Mapping
At present, the popular programming languages, such as Java and C #, are object-oriented programming languages, while the current mainstream database products, such as Oracle and DB2, are still relational databases. The uncoordinated development of programming language and underlying database (impedance mismatch, for example, the characteristics and behaviors such as storage inheritance, polymorphism and encapsulation cannot be directly realized in the database) gave birth to ORM framework. ORM framework can be used as a bridge between object-oriented language and relational database.
2、 Hibernate
Hibernate is an open source object relational mapping framework. It encapsulates JDBC with very lightweight objects, so that Java programmers can use object programming thinking to manipulate the database at will.
3、 The configuration method of Hibernate Framework under eclipse, here we take hibernate 3.0 as the example 2 as an example, let's introduce hibernate 3 2. Configuration method in Eclipse:
(1) Open eclipse, set its workspace, and click OK to enter the main interface of eclipse.
(2) First, we create a java project. File - > New - > java project - > create the project name. Here we take ones as an example.
(3) Import the jar packages we need. Here, we need to import three types of jar packages. First, hibernate3.jar, which is a necessary library when using hibernate. All files in the Lib file. The database is connected to the jar package. Here, we use the MySQL database file. The jar package we need to import is mysql.jar. Here, we create a user's own class library, which can directly import our jar package Enter the user library. When we create other projects, we avoid importing jar packages one by one.
The creation steps are shown in the figure:
(4) Click add external jars... To import the above jar package, click OK and finish to complete the operation. At this time, a user-defined class library named first can be seen under the project name.
(5) We import the hibernate.cfg.xml file in the SRC file directory. What we need to change here is line 7, localhost / ones (changes ones to its own database name)
The 9th line is the MySQL user name, and the 10th line is the password of the MySQL database. Delete line 14.
(6) Create user classes and mapping files under Src. Right click SRC - > New - > class - > select the class name. Here we create a class named user.
(7) Write the user class code (here eclipse supports batch automatic writing of set / get methods). Click source - > generate ftters and setters, select all and import. The user class has been written. Next, we will write the mapping file.
(8) Select the user.hbm.xml file and copy it into the package under the SRC folder. The file is located in Hibernate \ RG \ ORG \ hibernate \ auction. Here, the code we want to modify is line 6, and org.hibernate.auction is changed to the package name of our own project. The code in line 8 can only keep < class name = "user" >, the rest can be deleted. Delete the ninth line of code. Delete the native in line 12. The native is used to configure shaping data. The ID we previously set is character type, so here we change it to UUID. Delete lines 15 to 50. Write the attribute in < class >, and the attribute value is equal to user Attributes defined in Java (excluding ID).
(9) Written user hbm. The XML file is shown in the figure below:
(10) Write an import class, create a class called exportdb, and directly generate its main method
(11) Modify hibernate cfg. XML, change the path to ones (package name) / user hbm. xml
(12) Create a test table in the MySQL database, run the exportdb file in eclipse, and right-click - > run as - > java application
The above configuration method based on Hibernate Framework under eclipse (must see article) is all the content shared by Xiaobian. I hope it can give you a reference and support more programming tips.