JPA 2.0通过
@ElementCollection注释可以支持原语集合,你可以将其与
java.util.Map集合支持一起使用。这样的事情应该起作用:
@Entitypublic class Example { @Id long id; // .... @ElementCollection @MapKeyColumn(name="name") @Column(name="value") @CollectionTable(name="example_attributes", joinColumns=@JoinColumn(name="example_id")) Map<String, String> attributes = new HashMap<String, String>(); // maps from attribute name to value}另请参见(在JPA 2.0规范中)
- 2.6 - Collections of Embeddable Classes and Basic Types
- 2.7 Map Collections
- 10.1.11 - ElementCollection Annotation
- 11.1.29 MapKeyColumn Annotation



