Difference between Set and Bag in Hibernate?

There are following difference between Set and Bag in Hibernate.We are do mapping inside hbm file.
Bag :-
A Bag in Hibernate is an unordered collection. It can have duplicate elements. When we persist an object in a bag, there is no guarantee that bag will maintain any order.
There is not a “bag” concept in Java collections framework, so we just use a java.util.List corresponds to a <bag>.

				
					<bag name="student" table="stdent" inverse="true" lazy="true"
	fetch="select">
	<key>
		<column name="studentId" not-null="true" />
	</key>
	<one-to-many class="com.Student" />
</bag>
				
			

Set :-
A Set in Hibernate can only store unique objects. If we add the same element to set second time, it just replaces the old one. By default a Set is unordered collection in Hibernate.
A set is unordered by default but we can ask it to be sorted. The corresponding type of a in Java is java.util.Set.

				
					<set name="student" table="student" inverse="true" lazy="true"
	fetch="update">
	<key>
		<column name="student_id" not-null="true" />
	</key>
	<one-to-many class="com.Student" />
</set>