Hibernate Many-to-One mapping

Many-to-One relationship in real world: Two items are said to be in Many-to-One relationship if one item is belong to the many occurrences of other item. E.g. Many employees – one department. Many-to-One relationship in programming: Two entities are said to be in Many-to-One relationship if one entity belongs to many occurrence of other entity. … Read more

Hibernate One-to-Many mapping

One-to-Many relationship in real world: Two items are said to be in One-to-Many relationship if one item is belong to the many occurrences in other item. E.g. One department, many employees. One-to-Many relationship in programming: Two entities are said to be in One-to-Many relationship if one entity has many occurrence in other entity. Example: Student.java … Read more

Hibernate One-to-One Mapping

One-to-One relationship in real world: Two items are said to be in One-to-One relationship if one item is only belong to other. E.g. One person has one passport. One-to-One relationship in hibernate mapping: Two entities are said to be in One-to-One relationship if one entity has only one occurrence in other entity. Example: Student.java /** … Read more

Hibernate association mappings

Association: Association between two or more things is refers to the state of being associated i.e. how the things are related to each other. Association in hibernate tells the relationship between the objects of POJO classes i.e. how the entities are related to each other. Association or entities relationship can be unidirectional or bidirectional. Ways … Read more

Hibernate SortedMap mapping

SortedMap in collection: SortedMap is map which maintains its entries in ascending key order. SortedMap mapping: If an entity has a SortedMap of values for a property then this property can be mapped by using <map> element. A map is initialized with java.util.TreeMap. Example: Student.java import java.util.SortedMap; /** * This class represents a persistent class for … Read more

Hibernate Map mapping

Map in collection: A map represents an object with key value pair.  A map cannot contain duplicate keys and one key can map to at most one value. Map mapping: If an entity has a map of values for a property then this property can be mapped by using <map> element. A map is initialized with java.util.HashMap. … Read more

Hibernate bag mapping

Bag in collection: A bag is a java collection which can contain duplicate elements without caring about sequence element. We can get the information like the number of times an object appears in the collection by using bag. Bag works like a list without index (you don’t know what is the order of elements), so … Read more

Hibernate list mapping

List in collection: A List represents an ordered or sequenced group of elements. It may contain duplicate elements. Note: Elements can be inserted or retrieved by their position in the list. Position or index value starts from 0. List interface defines its own methods in addition to the methods of collection interface. List mapping: If … Read more

Hibernate SortedSet mapping

SortedSet in collection: SortedSet is a group of elements which not contain a duplicate element and maintain ascending order in its elements. SortedSet mapping: If an entity has a SortedSet of values for a property then this property can be mapped by using <set> element. A SortedSet is initialized with java.util.TreeSet. Example: Student.java import java.util.SortedSet;   … Read more

Hibernate Set mapping

Set in collection: A set represents a group of elements which can’t contain a duplicate element. Set mapping: If an entity has a set of values for a property then this property can be mapped by using <set> element. A set is initialized with java.util.HashSet. Example: Student.java import java.util.Set;   /** * This class represents … Read more