Xiao Bai self-taught HIBERNATE5.0 document the first-quarter domain model

Source: Internet
Author: User

2. Domain Model

The term domain model comes from the realm of data modeling. It's the model that ultimately describes, the problem domain you were working in. Sometimes you'll also hear the term persistent classes.

The term domain model comes from the field of data modeling, which is the problem domain model that you are ultimately describing in your work. Sometimes you will also hear the term persistence class.

Ultimately the application domain model is the central character in an ORM. They make up the classes-wish to map. Hibernate works best if these classes follow the Plain old Java Object (POJO)/JavaBean programming model. However, none of these rules is hard requirements. Indeed, Hibernate assumes very little about the nature of your persistent objects. You can express a domain model in other ways (using trees java.util.Map of instances, for example).

The final application domain model is the control role in ORM. They make up the classes you want to map. Hibernate works best if you follow the normal Java object (POJO)/javabean design model. However, these are not hard requirements. Indeed, Hibernate bears very little to do with your persistence object. You can express domain models in other ways (for example, using the map instance tree structure).

Historically applications using Hibernate would has used its proprietary XML mapping file format for this purpose. With the coming of JPA, most of this information are now defined in a-on-the-is portable across ORM/JPA providers using a Nnotations (and/or standardized XML format). This chapter would focus on JPA mapping where possible. For Hibernate mapping features is supported by JPA we'll prefer Hibernate extension annotations.

From a historical point of view, using Hibernate will require the use of its proprietary XML mapping file format for this purpose (in this case, the format model), with the advent of JPA, most of the information is now defined conveniently through ORM/JAP to provide usage annotations (or standard XML format). This chapter maps the centralized JPA to possible scenarios.

2.1. Mapping types

Hibernate understands both the Java and JDBC representations of application data. The ability to read/write this data from/to the database is the function of a Hibernate type. A type, in this usage, was an implementation of the org.hibernate.type.Type interface. This Hibernate type also describes various aspects of behavior of the Java type such as how to check for equality Clone values, etc.

Hibernate understands the representation of Java and JDBC application data. The ability to read/write data to/from the database is hibernate type. A type, this usage isorg.hibernate.type.Type 接口的实现。

Hibernate types also describe the behavior aspects of various Java types, such as how to check for equality, how to clone values, and so on.

To help understand the type categorizations, let's look at a simple table and domain model so we wish to map.

To help understand this type of classification, let's look at a simple table where we want to map the domain to the model.



In the broadest sense, Hibernate categorizes types into two groups: 
 
In a broad sense, the hibernate classification types are divided into two groups:
    • Value types

    • Entity types

 
2.1.1. Value types

A value type is a piece of data, does not define its own lifecycle. It is, in effect, owned by a entity, which defines its lifecycle.

  A value type is a fragment that cannot define its own life cycle data, by an entity , define its life cycle. 

looked at another, all the state's an entity is made up entirely of value types. These state fields
or JavaBean Properties are termed persistent attributes. The persistent attributes of the  contact  class is
< Span style= "font-family:"microsoft yahei"" >value types.
on the other hand, the declaration of all entities constitutes a complete value type. These declaration properties or the JavaBean property

Value types is further classified into three sub-categories:

  Value types are further categorized as 3 subcategories:

Basic types

Contactin mapping the table, all attributes except for name would is basic types. Basic types is discussed in detail in basic types

embeddable types

The name attribute is a example of an embeddable type, which was discussed in details in embeddable Types

Collection types

Although not featured in the aforementioned example, collection types is also a distinct category among value types. Collection types is further discussed in collections

Basic type:

Map to the Contact table, all attributes except the name as the underlying type.

Embeddable types:

The name attribute is an example of a nested type.

Collection type: Although not the attribute mentioned above, the collection type is also a classification that differs from the value type.

2.1.2. Entity types

  Entities, by nature of their unique identifier, exist independently of the other objects whereas values does not. Entities is domain model classes which correlate to rows in a database table, using a unique identifier. Because of the requirement for a unique identifier, entities exist independently and define their own lifecycle. The Contact class itself would be a example of an entity.

Mapping entities is discussed in detail in Entity.

  

  Entities, which have values that are independent of other objects, through the nature of their unique identifiers. The entity Domain model class is associated to a column in the data, using a unique identifier. Because a unique identifier is required, the entity has a descriptive detail of the mapped entity in the Entity section.

  

2.2. Naming Strategies

Part of the mapping of a object model to the relational database was mapping names from the object model to the correspond ing database names. Hibernate looks at this as 2 stage process:

    • The first stage is determining a proper logical name from the domain model mapping. A logical name can be either explicitly specified by the user (using @Column or @Table e.g.) or it can implicitly determin Ed by Hibernate through an implicitnamingstrategy contract.

    • Second is the resolving of this logical name to a physical name which are defined by thephysicalnamingstrategy contract.

  

The mapping part of the object model associates the database mapping name from the object model to the corresponding database name. Hibernate looks at the two stage process:

The first stage is to determine the appropriate logical name from the domain model mapping. The use of a logical name can be clearly specified (using @Column or @Table e.g) or can be implicitly determined through Hibernate's Implicitnamingstrategy convention.

The second is to parse the logical name to the physical name definition through the Physicalnamingstrategy convention.

  The historical naming strategy protocol

The history of hibernate definition is just a singleton org.hibernate.cfg.NamingStrategy. The single Namingstrategy protocol, in effect, separates the current pattern of concerns like Implicitnamingstrategy and Physicalnamingstrategy. And the Namingstrategy protocol is often inflexible enough to properly apply a given naming "Rules" should also be a lack of information for the API to determine or because the API too honest can not be well defined.

Due to these limitations, Namingstrategy was deprecated and then removed in favor of using Implicitnamingstrategy and Physicalnamingstrategy

At the core, the idea behind each naming strategy are to minimize the amount of the repetitive information a developer must pro Vide for mapping a domain model.

The central idea, the mapping domain model that each of the naming policy information developers must provide at the end of the ideas, minimizes the number of repetitions.

JPA compatibility

JPA defines inheritance rules for implicit logical name speculation. If the JPA provider portability is a major concern, or if you are really just defining implicit naming rules like JPA, you can stick with the default Implicitnamingstrategyjpacompliantimpl. Similarly, the JPA definition does not separate logical names from physical names. If the JPA provider portability is important, the application should not specify this policy physicalnamingstrategy.

Egg-ache translation .... Foggy ....

Xiao Bai self-taught HIBERNATE5.0 document the first-quarter domain model

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.