@ElementCollection 组件集合映射
相关资料
http://docs.oracle.com/javaee/6/api/javax/persistence/ElementCollection.html
https://jazzy.id.au/2008/03/24/jpa_2_0_new_features_part_1.html
一维数组或集合
private List<String> tags;
直接在属性或get方法上配置注解:
@ElementCollection @CollectionTable(name = "VEH_SVC") @OrderBy("serviceDate")
二或多维维数组或集合
private List<List<String>> tags;
需要将第二维度封装:
@ElementCollection(fetch=FetchType.EAGER) List<EmbeddedChild> children = new ArrayList<EmbeddedChild>();
EmbeddedChild:
@Embeddable public class EmbeddedChild { @ElementCollection(fetch=FetchType.EAGER) List<EmbeddedGrandChild> children = new ArrayList<EmbeddedGrandChild>(); }
转载请注明:晓窗博客 » JPA关于集合或数组注解配置方式