aspose file tools*
The moose likes Object Relational Mapping and the fly likes CollectionsInHibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "CollectionsInHibernate" Watch "CollectionsInHibernate" New topic


kishor kalapa

Joined: Jun 05, 2008
Posts: 24
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.
Don't get me started about those stupid light bulbs.
subject: CollectionsInHibernate
Similar Threads
Hibernate Issue
Hibernate exception for one-to-one mapping
CascadeType.PERSIST not working
Mapping Error Hibernate
Exception while inserting a row using Hibernate