Example of @CollectionId in Hibernate
May 31, 2013
@CollectionId is used to create a collection id. And that id will work as primary key. Bag collections id do efficiently removal and insertion of rows. @CollectionId is used as
@CollectionId(columns = @Column(name="collection_id"), type=@Type(type="long"), generator = "country_id_gen" )
Country.java
@Entity public class Country implements Serializable { private static final long serialVersionUID = 1L; ------------------ @Column(name="name") private String name; @ManyToMany @JoinTable(name="state") @CollectionId(columns = @Column(name="collection_id"), type=@Type(type="long"), generator = "country_id_gen" ) private Collection<State> states = new ArrayList<State>(); ----------------- }