Recall that when we did not learn ssh, when we build the database table, the first is the database modeling e-r diagram, and then through the entity model to establish the relationship model, and then establish the corresponding table. There are three relationships between entities, one-to-many (or many-to-two), many-to-many. And now we're going to map the table based on the class, which can only be mapped by mapping files to the relationship between
="4" sql-type="int" not-null="true" unique="true"/>"native" />--对象Person的Name属性和表t_Person中字段t_Name建立映射关系-->name="Name" type="String">column name="t_Name" length="50" sql-type="varchar" not-null="false"/>"font-family:FangSong_GB2312;font-size:18px;">
This is the map file generated by the table automatically nhibernate and mapping class (that is, we have handwritten entity) the approximate use of the method, is not very simple it?! It saves a lo
Set Set mapping
Set set mapping is simple, I feel a bit like a one-to-many relationship (only a single PO's a-to-many relationship), because it can be a table and two hibernate necessary configuration, a run class on it.
The code is as follows (for example, people address)
First write the JavaBean model class (person)
Package one;
Import Java.util.Set;
Unidirectional one-to-many association mappingsThe mapped relational model:Map file:A one-to-many correlation mapping and a multiple-to-one correlation mapping principle are consistent, with the addition of a foreign key to one end of a multi-pointThe difference between them is that they maintain different relationships:* Many-to-one maintenance relationship is: a multi-point relationship, with this relatio
1. Follow the foreign key mapping ( Hibernate provides two ways to map one-to-one relationships: by foreign key mapping and by primary key mapping Implementation needs:Create an entity class Users1 and Resume1 Publicclass Users1 {Private Integer userid;Private String username;Private String Userpass;Private Resume1 res
on A study Hibernate The basic mapping, that is, single-table mapping, it is easy to understand, but for the relational database, the existence of a relationship between tables is not very small, the relationship between the database is established through the main foreign key , the reaction to Hibernate How do you
One-way many-to-many association mappingsOne-way many-to-many association object model:The mapped relational model:Many-to-many mappings produce a third table to maintain relationshipsMap file:User.hbm.xml[HTML]View Plaincopyprint?
XML version="1.0"?>
"-//hibernate/hibernate Mapping DTD 3.0//en"
"Http://hibernate.sourceforge.net/
ObjectiveFor Java developers, annotations should not be an unfamiliar concept, as early as the javase phase, such as the @override tag overriding the parent class method or implementing an interface method, @Test tag unit test method, so we can simply interpret it as a tag with special meaning ... In the development process, we can also use annotations to replace the configuration file implementation of related features, such as Java Web Development, 3.0 version, the use of @webservlet, @WebList
Take the message system as an example1. Configure the mapping file: first you have to introduce a constrained DTD"-//hibernate/hibernate Mapping DTD 3.0//en""Http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" >Then The 2. Cor
"SSH Advanced Path" Hibernate fundamentals (i) , the small part introduces the basic principle of hibernate and its core, and adopts the object-oriented thinking operation relational database. "SSH Advanced path" hibernate build development environment + Simple example (ii) , the small series built the basic Hibernate
The Hibernate ing file contains a hibernate-mapping element, which includes optional attributes, such:
(1) Schema (optional): name of the database schema.
(2) catalog (optional): name of the database catalog.
(3) default-cascade (optional-the default value is none): the default cascade style.
(4) default-access (optional-property by default): the policy tha
ORM. The full name is (objectrelational Mapping), which is the objects relational mapping. The idea of ORM is to map the data of tables in a relational database into objects. Presented in the form of objects. This enables developers to translate the operations of the database into operations on those objects. Hibernate is the realization of this idea, to facilita
"SSH Advanced Path" Hibernate fundamentals (i) , the small part introduces the basic principle of hibernate and its core, using the object-oriented thinking operation relational database. "SSH Advanced path" hibernate build development environment + Simple example (ii) , Xiao-bian set up the basic hibernate development
"SSH Advanced Path" Hibernate fundamentals (i) , the small part introduces the basic principle of hibernate and its core, using the object-oriented thinking operation relational database. "SSH Advanced path" hibernate build development environment + Simple example (ii) , Xiao-bian set up the basic hibernate development
Example Object Model:There are three ways to implement inheritance mappings:(i) one table for each class of tree inheritanceRelational Model:Map file:[HTML]View Plaincopyprint?
hibernate-mapping package="Com.jialin.hibernate">
class name="Animal" table="T_animal" lazy="false">
ID name="id">
generator class="native"/>
ID>
discriminator column="type" type="string"/>
prop
( ); Session.close ();} @Testpublic void Testget () {Session session=sf.opensession (); Session.begintransaction ();//query q= Session.createquery ("from Cat");//listMapping files can also be divided into three types to implement one, all sub-classes mapped to a table (1 tables)What's the use of?Subclasses teach many, and subclasses are simpler, that is, only individual attributes!Benefit: Because a mapping file is used, the number of
Object Relational Mappings ( ORM ) has been introduced in the previous blog post: ORM IntroductionThis blog post is mainly to introduce Hibernate The basic mappingConceptRelationship: The state of interacting and connecting things.Association: Associating Objects (database tables) in some wayMapping: Converting one form to anotherBasic mapping: There is no connection between table and table (dictionary tabl
Previous blog post "SSH Advanced path" hibernate mapping-one-to-one unidirectional correlation mapping (v), we introduced one-to-two unidirectional association mappings, one-way refers to the only people (person) on this side to load the identity card (Idcard), but in turn, can not be added from the identity card side information. :The key reason is that the obj
Component mappingIn hibernate, the component map uses Component is the logical component of an entity, and the main difference between it and the entity class is that it has no OIDComponent is called a value class in DDDThe advantages of using component: To realize the fine-grained division of the object model, high reuse rate, clear meaning and distinct hierarchyObject model and relational model design on the contrary, the object model is generally f
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.