Hibernate o/r Mapping-Collection Mappings


Hibernate o/r Mapping-Collection Mappings

If a variable is an entity or class with a collection of values, we may use Java's collection interfaces to map those values.

Hibernate mappings are one of Java's most important features. As attributes in your model, they create the link between two database tables, making it simple to explore the relationships in your model and criterion queries.

You may make them unidirectional or bidirectional, meaning you can use them as a property on either one or both of the connected entities. It does not affect your database mapping tables, but it does specify the direction in which the connection may be used in model and criterion queries.

Collection Mappings

Hibernate enables collection mapping as a value type, and the collection is mapped into a separate table in this mapping.

When we need to save a class's property, whether it's a data type like integer, long, float, or an object of a wrapper class like a String, we save it directly in the class's table. If the class property is a collection type, we'll need to keep it in a separate collection table.

  • As value types, Hibernate supports the following collection interfaces:
  • java.util.
  • Set- does not allow duplicates and does not keep track of the order.
  • set> is mapped to Implementation of Hibernate should include HashSet.

java.util.SortedSet- performs in-memory sorting and is mapped to the hibernating set> element, with the sort property used to customise the comparator implementation. TreeSet

  • java.util. List-allows duplicates and preserves insertion order is mapped to the hibernating list> element, and the list-index property is used to retain the index (position). ArrayList

The java.util. The collection class allows for duplicates and does not keep track of insertion orders.
ArrayList should be mapped to the hibernate implementation's bag> or idbag> element.
java.util.A key-value pair is referred to as a map.

  • The implementation of is mapped to map> should be HashMap.

java.util.SortedMap- is a key-value pair that performs sorting in memory.