Reprinted on:
http://blog.9cbs.net/roSen/archive/2004/11/12/179646.aspx
First of all, I would like to thank my TEAM aware of the shortcomings of traditional JDBC development, and began to pay attention to the results of O / R mapping. Speaking of O / R Mapping, I think it is a good choice when the object database has not really mature, look at the Sun's JDO 2.0 specification, its upcoming release will push this field to a higher realm. Let's take a look at our open source community, hey! Found Hibernate! From now on, my focus will be placed on Hibernate, an excellent O / R mapping tool.
Let us distinguish between several nouns before you have not officially started trip. POJO: On Hibernate represents the value object that contains the most basic operations of SETER, GETER. BO: represents the value object containing some business logic, its role domain, that is, BO can pass to the UI layer while serving as a lasting class. PO: Represents a persistent object, which is incorporated into the Hibernate management framework. To a certain extent, it can be interchanged with the concept of value objects, and the value object has been processed by hibernate, it will become PO. Hibernate profile: hibernate.cfg.xml or hibernate.properties, but it is recommended to use XML format. Mapping file * .hbm.xml: The role of the mapping file is to bind POJO to the relational database data as a bridge. In addition, it is not a good thing for the table in the database. Fortunately, there are also a group of people who have the same idea in the open source community. They have developed HibernateSynchronizer mapping tools to http://www.binamics.com/hibernateSync/ Eclipse2.1 / download.
Ok, now go to http://www.hibernate.org to download the Hibernate development package (the current version is 2.1.6). Then open Eclipse 2.1 and install HibernateSynchronizer in the Update Manager. It is said that Eclipse 3.0 has built-in mapping tools, but I didn't try it. After installation, create a web application HibernateTest, then add Hibernate library hibernate-2.1.6/ hibernate-2.1 / hibernate2.jar and its dependencies, database connection packages, strongly recommended to put Hibernate-2.1. All class libraries under 6 / hibernate-2.1 / lib load, as shown below:
Then use
HibernateSynchronizer
Generate
Hibernate.cfg.xml
File, new
>
other--
> Hibernate Configuration File
, I am using
SQL Server
Database, each configuration parameter is shown below: Supplement: Press Browse on the right side of the Driver File in Hibernate Configration File, fill in the hibernate.cfg.xml file generated by com.microsoft.jdbc.sqlserver.sqlserverdriver in Select Entries: in the project New four packages in the SRC directory are Bo, Bo.Base, bo.mapping, com.dao, what role, when they will present it one by one. Do one thing before starting the mapping file, configure HibernateSynchronizer for the application HibernateTest, I prefer to write DAO, so I don't have Data Access Objects, and the other parameters are as follows: The mapped table AutoInfo structure is as follows, ID is Its primary key: New -> Others-> Hibernate Mapping File, after configuring the parameter "Refresh", select the table you want to map, pay attention not to map the file at 800 * 600! Otherwise, some buttons do not appear, each configuration parameter is shown below: Supplement: Press Browse on the right side of the Driver Maping File, fill in the com.microsoft.jdbc.sqlserver.sqlserverdriver in Select Entries.
Database URL Fill in: JDBC: Microsoft: SQLServer: // localhost: 1433; DatabaseName = YourDatabaseName and press the Refresh button. My computer error: Error establishing connection [Microsoft] [SQLServer 2000 Driver for JDBC] Error establishing socket.google for a long time and found that: as long as the windows 2003 SQLServer2000 will have this problem, because the problem is because of security sqlserver2000 windows2003 default banned. As long as the SQLServer 2000 SP3 patch is successful.
Finally, finally, the mapping file autoinfo.hbm.xml finally came out!
XML Version = "1.0"?>
Replace with:
Make persistent efforts to generate POJO for the mapping file. Modify the Hibernate.cfg.xml file in the session-factory> tab, add the files just mapped
(Note that the reference should indicate the original author posted this article:! Rosen Jiang and the source:
http://blog.9cbs.net/rosen
)