Home  >  Hibernate

Example of @CollectionId in Hibernate

By Arvind Rai, 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" )
 
Find the code snippet.

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>();
	-----------------
}
 
POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS







Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us