Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

CollectionsInHibernate  RSS feed

Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package com.coll.clients;

import java.util.HashSet;
import java.util.Set;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import com.coll.pojos.Images123;
import com.coll.pojos.Item123;

public class CollectionKing {

* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
SessionFactory sf=new Configuration().configure().buildSessionFactory();
session s=sf.openSession();
Transaction tx=s.beginTransaction();
Images123 i=new Images123(); //1*********
Images123 i1=new Images123(); //2**********
Item123 it=new Item123();
Set set=new HashSet();
it.setItemDescription("Car is very good");


package com.coll.pojos;

public class Images123 {
private int itemId;
private String fileName;

public int getItemId() {
return itemId;
public void setItemId(int itemId) {
this.itemId = itemId;
public String getFileName() {
return fileName;
public void setFileName(String fileName) {
this.fileName = fileName;

------------------------------------------------------------------------ :

package com.coll.pojos;

import java.util.HashSet;
import java.util.Set;

public class Item123 {
private int itemId;
private String itemName;
private String itemDescription;
private Set images=new HashSet();
public int getItemId() {
return itemId;
public void setItemId(int itemId) {
this.itemId = itemId;
public String getItemName() {
return itemName;
public void setItemName(String itemName) {
this.itemName = itemName;
public String getItemDescription() {
return itemDescription;
public void setItemDescription(String itemDescription) {
this.itemDescription = itemDescription;
public Set getImages() {
return images;
public void setImages(Set images) {
this.images = images;


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "" >
<hibernate-mapping package="com.coll.pojos">
<class name="Item123" table="item">
<id name="itemId" column="item_id">
<property name="itemName" column="name"></property>
<property name="itemDescription" column="description"></property>
<set name="images" table="item_image">
<key column="ITEM_ID"></key>
<element type="string" column="FILENAME" not-null="true"></element>
cfg file:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"

<!-- Generated by MyEclipse Hibernate Tools. -->

<property name="connection.username">root</property>
<property name="connection.url">
<property name="dialect">
<property name="myeclipse.connection.profile">RaviDriver</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">
<property name="">update</property>
<property name="show_sql">true</property>
<mapping resource="com/coll/pojos/primarycollection-hbm.xml" />


when I run the I am getting ClasscastException on image123(as element) insertion into images(set),if I am replace set element as string program runnig fine.
Can any one mention changes required to run for set element as Images123.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!