In Hibernate, is it possible for a field of an entity to be a List whose elements are…
- User
In Hibernate, is it possible for a field of an entity to be a List whose elements are marked as embeddable?
- Assistant
Yes, in Hibernate it is possible for a field of an entity to be a List whose elements are marked as embeddable. This can be achieved by using the
@ElementCollectionannotation in combination with the@Embeddableannotation.Here's an example:
java@Entity public class ParentEntity { @Id private Long id; @ElementCollection private List<ChildEmbeddable> children; // other fields, constructors, getters, setters } @Embeddable public class ChildEmbeddable { private String name; private int age; // other fields, constructors, getters, setters }