I’m using Hibernate to store a data model, which has a number of simple fields:
@Entity
public class Shape extends DomainObject {
@LazyCollection(LazyCollectionOption.FALSE)
@CollectionOfElements()
private List<Shape> children;
@Column
private int numSides;
... etc. ...
}
The DomainObject superclass keeps track of the Long id.
We’d like to make a change to the children List, so that instead of being a simple List, it’s actually a Map where the key is the Long id (from the superclass).
@???
private Map<Long, Shape> children;
How are migrations/type changes of this nature handled in Hibernate? I’m not too familiar with this aspect of Hibernate – is there some method that can be overloaded to accept the List<Shape> (on the first load of the application, using the older data) and perform a manual generation of the new Map?
There shouldn’t be any difference in the database: you just choose to use a Map rather than a List to store the Shapes, but the attributes of the Shape entity stay identical and thus the table storing the shapes also has the same columns.