我需要create和elementcollection属性,但我需要在集合中添加额外的列,如替代名称。
上面在mkyong网站上描述了所有实体。
@Entity
@Table(name = "stock", catalog = "mkyongdb", uniqueConstraints = {
@UniqueConstraint(columnNames = "STOCK_NAME"),
@UniqueConstraint(columnNames = "STOCK_CODE") })
public class Stock implements java.io.Serializable {
private Integer stockId;
private String stockCode;
private String stockName;
@ElementCollection
@OneToMany(fetch = FetchType.LAZY)
@MapKeyColumn(name = "indice")
private Map<Integer,StockCategory> stockCategories = new HashMap<Integer,StockCategory>();
...
}
https://www.mkyong.com/hibernate/hibernate-many-to-many-example-join-table-extra-column-annotation/