admin 管理员组文章数量: 1087135
2024年4月23日发(作者:个人博客登django)
内蒙古工业大学本科毕业设计外文文献翻译
Hibernate simplifies inheritance mapping
Hibernate is an object-relational mapping and persistence framework that provides a
lot of advanced features, ranging from introspection to polymorphism and inheritance
mapping. But mapping class hierarchies to a relational database model might prove
somewhat difficult. This article covers three strategies that you can use in your everyday
programming to easily map complex object models to relational database models.
Overview
Hibernate is a pure Java object-relational mapping and persistence framework that
allows you to map plain old Java objects to relational database tables using XML
configuration files. Using Hibernate can save a lot of development time on a project, since
the whole JDBC layer is managed by the framework. This means that your application's
data access layer will sit above Hibernate and be completely abstracted away from of the
underlying data model.
Hibernate has a number of advantages over other similar object-relational mapping
approaches (JDO, entity beans, in-house development, and so on): it's free and open source,
it has achieved a good level of maturity, it's widely used, and it has a very active
community forum.
To integrate Hibernate into an existing Java project, you'll need to walk through the
following steps:
1. Download the latest release of the Hibernate framework from the Hibernate Web
site. Copy the necessary Hibernate libraries (JAR files) to your application's
CLASSPATH.
2. Create the XML configuration files that will be used to map your Java objects to
your database tables. (We'll describe that process in this article.)
3. Copy the XML configuration files to your application's CLASSPATH.
You'll notice that you don't have to modify any Java objects to support the framework.
Imagine, for instance, that you needed to somehow change a database table that your Java
1
内蒙古工业大学本科毕业设计外文文献翻译
application used -- by renaming a column, for example. Once you'd changed the table, all
you'd have to do to update your Java application would be to update the appropriate XML
configuration file. You wouldn't need to recompile any Java code.
Hibernate Query Language (HQL)
Hibernate provides a query language called Hibernate Query Language (HQL), which
is quite similar SQL. For those of you who prefer good old-fashioned SQL queries,
Hibernate still gives you the opportunity to use them. But our supporting example will use
HQL exclusively.
HQL is quite simple to use. You will find all the familiar keywords you know from
SQL, like SELECT, FROM, and WHERE. HQL differs from SQL in that you don't write
queries directly on your data model (that is, on your tables, columns, etc.), but rather on
you Java objects, using their properties and relationships.
Listing 1 illustrates a basic example. This HQL code retrieves all Individuals whose
firstName is "John."
Listing 1. Basic HQL Query
SELECT * FROM dual WHERE firstName =
"John"
You can refer to the HQL reference material on the Hibernate Website if you want to
learn more about HQL syntax.
XML configuration files
The core of Hibernate's functionality resides inside XML configuration files. These
files must reside in your application's CLASSPATH. We placed them in the config
directory of our sample code package
The first file that we'll examine is . It contains information regarding
your data source (DB URL, schema name, username, password, etc.) and references to
other configuration files that will contain your mapping information.
The remaining XML files allow you to map Java classes against database tables. We
will take a closer look at those files later, but it is important to know that their filenames
follow the pattern .
Our supporting example
2
版权声明:本文标题:Hibernate 简化继承映射 外文翻译 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/b/1713819502a652977.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论