The nature of relevance mapping:
* Mapping an association relationship to a database, the so-called association relationship is one or more references in memory of the object model
If this property is omitted, the default foreign key is the same as the entity's property
Example of the definition of
*
1, User's Pojo class:
1public class User { 2 3 private int id; 4 5 private String name; 6 7 pri
1
Package Com.sm.hibernate.pojo;
Import Java.util.Set;
public class User {
private int id;
private String name;
private int QQ;
Private Grade Grade;
Private set
Here are the most important two points, one is the discriminator, one is a subclass declaration, integral
2
Inheriting classes
Package Com.sm.hibernate.pojo;
public class Guest extends user{
private String email;
Public String Getemail () {return
email;
}
public void Setemail (String email) {
This.email = em
A one-to-one relationship mapping is a reference that both sides of the relationship contain each other. In fact, a one-to-one relationship in life is also very common, such as people and identity cards, students and school numbers, are one-to-one relationship mapping, one-to-one mapping into one-way and two-way, there is no kind of relationship
structure
Disadvantage: The primary key for two child tables cannot be duplicated, and the primary key cannot be generated using the database's self-amplification method.
"2": Advantages: High query efficiency, in line with database design coarse granularity (recommended)
Disadvantage: There are redundant fields, some of which are attributes that subclasses do not have.
"3": Advantages: Clear data structure, no redundancy
Disadvantages: The class of inheritance more than the same, resulting in
This article will describe the basic configuration of hibernate and the application of the configuration file, which is very important for the correct proficiency in the use of hibernate.
detailed mapping elements in the configuration file
The mapping of object relationships is illustrated with an XML document.
Hibernate is an open source object-relational mapping framework that provides JDBC with a very lightweight object encapsulation that maps Pojo to database tables, is a fully automated ORM framework, and Hibernate automatically generates SQL statements, automatically executes, So that Java programmers can use object programming thinking to manipulate the database
Brief introduction:The mapping between the POJO class and the relational database can be defined with an XML documentWith the POJO class's database mapping file, Hibernate can understand the relationship between persisted classes and data tables, as well as the relationship between persisted class properties and database table columns.Hibernate will generate vari
Hibernate is an open source object-relational mapping framework that provides JDBC with a very lightweight object encapsulation, which speaks of pojo mapping with database tables, is a fully automated ORM framework, hibernate can automatically generate SQL statements, automatically execute, Enables Java programmers to
Description of the configuration file hibernate-mapping is the root element of the hibernate mapping fileSchema: Specifies the name of the mapped database schema. Specifying this property indicates that the schema prefix is added automaticallyCatalog: Specifies the name of the mapped database catalog.Default-cascade (d
First, the principle of the use of composition relations :Minimizing the number of database tables and foreign key references between tables, without causing data redundancy, is a time-consuming operation to establish a connection to multiple tables.Example: The address attribute in the customer class can be mapped by component, avoiding an additional address table and achieving object-based operations.Configuration file:?
1 2 3 4 5 6 7
"homeAddress" class="mypack.Address">
Hibernate classification and integration found that in fact, hibernate is divided into three major parts: core objects, mapping, HQL, the most commonly used in the development process, the first several discussed the core objects and the transformation between objects, and then discuss the hibernate
Property> Mapping File Configuration - MappingResource= "Com/pb/entity/login.hbm.xml" /> session-factory>hibernate-configuration>Third, Entity mappingThe object-relational mapping in Hibernate is to correspond the entity class to the table in the database, implementing the attributes in the entity cla
1, the map file, the code is as follows: XML version= "1.0"?>DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "Http://www.hibernate.org/dtd/hib Ernate-mapping-3.0.dtd ">persisting the
Hibernate has been categorized into three major parts: The core object, the mapping, the HQL, the most commonly used in the three most development processes, the previous discussion of the transformation between the core object and the object, and then the use of Hibernate mapping method.first, basic usageOne of the im
"SSH Advanced Path" Hibernate fundamentals (i) , the small series introduces the basic principles of hibernate and its core. Using the object-oriented thinking operation relational database. "SSH Advanced path" hibernate build development environment + Simple example (ii) , the small series built the basic Hibernate de
before we say Hibernate mapping, let's look at the object-relational mapping ORM. The implementation idea of ORM is to map the data of tables in the relational database into objects, which are presented in the form of objects . This allows developers to translate the operations of the database into operations on those objects. Let's see a picture.With this
() {returnOrdername; } Public voidsetordername (String ordername) { This. Ordername =Ordername; } PublicCustomer GetCustomer () {returncustomer; } Public voidSetcustomer (Customer customer) { This. Customer =customer; } }So how does this two class relate to each other?Then you need to go through that. The Configure in the Order.hbm.xml file: Add a foreign key to the "many" sectionXML version= "1.0"?>DOCTYPE hibernate-
Transfer from http://blog.csdn.net/a9529lty/article/details/6454924The role of the Hibernate mapping file:Hibernate mapping file is a bridge for hibernate to persist with the databaseTwo, Hibernate mapping file main content:(1). D
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.