Hibernate JPA @ListIndexBase Example
@ListIndexBase
The @ListIndexBase annotation is used to specify the start value for a list index, as stored in the database.By default, List indexes are stored starting at zero. Generally used in conjunction with @OrderColumn.
ListIndexBase
Defines the start index value for a list index as stored on the database. This base is subtracted from the incoming database value on reads to determine the List position; it is added to the List position index when writing to the database. By default list indexes are stored starting at zero. Generally used in conjunction with OrderColumn.Customizing ordered list ordinal
You can customize the ordinal of the underlying ordered list by using the @ListIndexBase annotation.Example : @ListIndexBase mapping example
@OneToMany(mappedBy = "person", cascade = CascadeType.ALL)
@OrderColumn(name = "order_id")
@ListIndexBase(100)
private List<Phone> phones = new ArrayList<>();
When inserting two Phone records, Hibernate is going to start the List index from 100 this time.
Comments
Post a Comment