O / R Mapping
So far we have seen very foundation by applying Hibernate O / R mapping, but there are three more important topics related to the mapping we need a more detailed discussion. This topic is mapped set of three, and the associated mappings between entities class mapping assembly.
Map collection
If you have a set of values of a particular variable or an instance of class, then we can apply any of the available interfaces in Java to map these values. Hibernate can save java.util.Map, java.util.Set, java.util.SortedMap, java.util.SortedSet, java.util.List , and any other instances or continuous values array instances.
Collection Type | Mapping and description |
---|---|
java.util.Set | It \ <set> element and matching with java.util.HashSet initialization. |
java.util.SortedSet | It \ <set> element and matching with java.util.TreeSet initialization. sort attributes may be provided or a natural ordering comparator. |
java.util.List | It \ <list> element and matching with java.util.ArrayList initialization. |
java.util.Collection | It \ <bag> or \ <ibag> element matching and initialization java.util.ArrayList. |
java.util.Map | It \ <map> element and matching with java.util.HashMap initialization. |
java.util.SortedMap") | It \ <map> element and matching with java.util.TreeMap initialization. sort attributes may be provided or a natural ordering comparator. |
For the original values using Java's Hibernate <primitive-array>
support arrays, other values for Java Hibernate uses <array>
array support. However, they are rarely applied, so I will not discuss them in this guide.
If you want to map a user-defined set of interfaces and this interface is not directly supported by Hibernate, then you need to tell Hibernate the grammar you define a set, this operation is difficult and not recommended.
Association mapping
Class association mapping between entities and relationships between the tables is the soul of the ORM. A subset of the relationship between objects can be explained by the following four ways. Association mapping can be unidirectional can also be bi-directional.
Mapping Types | description |
---|---|
Many-to-One | Hibernate mapping many-to-use relationship |
One-to-One | Use Hibernate mapping one relationship |
One-to-Many | Use Hibernate mapping to-many relationship |
Many-to-Many | Use Hibernate mapping-many relationship |
Component Mapping
As a variable entity class and other classes are likely to have a relationship. If the referenced class does not have its own life cycle and have it entirely depends on the life cycle of the entity class, then this reference class therefore can be called component class.
Mapping component collection and mapping is likely similar to the normal collection, there will only be a few different settings. We can look at these two maps in the example.
Mapping Types | description |
---|---|
Component Mappings | Class map as a reference for the class as an additional variables. |