I am evaluating Hibernate for a critical OLTP application. I am developing a Proof-Of-Concept. I am making some silly mistakes being a newbie to Hobernate.
My error is similar to the one in this topic.
http://forum.hibernate.org/viewtopic.ph ... ttype+wrap
But I could not find any clue. Pl help me.
My Parent Class is
Code:
package com.media.myEVNTS;
import java.util.List;
import java.util.ArrayList;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class DistributorProgram {
String programID;
String programName;
int duration;
List episodes;
public DistributorProgram() {
episodes = new ArrayList();
}
public DistributorProgram(String programID, String programName, int duration) {
this();
this.programID = programID;
this.programName = programName;
this.duration = duration;
}
public DistributorProgram(String programName, int duration) {
this();
this.programName = programName;
this.duration = duration;
}
public void addEpisode(Episode episode) {
if (episodes == null) {
episodes = new ArrayList();
}
episode.setDistributorProgram(this);
episodes.add(episodes);
}
public void setEpisodes(List episodes){
this.episodes=episodes;
}
public List getEpisodes(){
return this.episodes;
}
public void removeEpisode(Episode episode) {
//to be implemented
}
public int getEpisodeCount() {
if (episodes != null) {
return episodes.size();
}
return 0;
}
public void setProgramName(String programName) {
this.programName = programName;
}
public String getProgramName() {
return this.programName;
}
public void setProgramID(String programID) {
this.programID = programID;
}
public String getProgramID() {
return this.programID;
}
public void setDuration(int programID) {
this.duration = duration;
}
public int getDuration() {
return this.duration;
}
}
My Child class is
Code:
package com.media.myEVNTS;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Episode {
String episodeID;
String episodeName;
int episodeNo;
DistributorProgram distributorProgram;
public Episode() {
}
public Episode(String episodeID, String episodeName, int episodeNo) {
this.episodeID = episodeID;
this.episodeName = episodeName;
this.episodeNo = episodeNo;
}
public Episode(String episodeName, int episodeNo) {
this.episodeName = episodeName;
this.episodeNo = episodeNo;
}
public void setEpisodeID(String episodeNo) {
this.episodeID = episodeID;
}
public String getEpisodeID() {
return this.episodeID;
}
public void setEpisodeName(String episodeName) {
this.episodeName = episodeName;
}
public String getEpisodeName() {
return this.episodeName;
}
public void setEpisodeNo(int episodeNo) {
this.episodeNo = episodeNo;
}
public int getEpisodeNo() {
return this.episodeNo;
}
public void setDistributorProgram(DistributorProgram program) {
this.distributorProgram = program;
}
public DistributorProgram getDistributorProgram() {
return this.distributorProgram;
}
}
My Mapping file is
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.media.myEVNTS.DistributorProgram" table="dist_program">
<!-- A 32 hex character is our surrogate key. It's automatically
generated by Hibernate with the UUID pattern. -->
<id name="programID" type="string" unsaved-value="null" >
<column name="PROGRAM_ID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<!-- A program has to have a name, but it shouldn' be too long. -->
<property name="programName">
<column name="PROGRAM_NAME" sql-type="varchar(16)" not-null="true"/>
</property>
<!-- A program has to have a name, but it shouldn' be too long. -->
<property name="duration">
<column name="PROGRAM_DURATION" sql-type="int" not-null="true"/>
</property>
<set name = "episodes" inverse="true" lazy="true" cascade="all">
<key column="PROGRAM_ID"/>
<one-to-many class="com.media.myEVNTS.Episode"/>
</set>
</class>
<class name="com.media.myEVNTS.Episode" table="episode" dynamic-update="true">
<id name="episodeID" column="EPISODE_ID" type="string" unsaved-value="null">
<column name="EPISODE_ID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="episodeName">
<column name="EPISODE_NAME" sql-type="varchar(16)"/>
</property>
<property name="episodeNo">
<column name="EPISODE_NO" sql-type="int"/>
</property>
<many-to-one name="distributorProgram" column="PROGRAM_ID" not-null="true"/>
</class>
</hibernate-mapping>
The error I am getting is as follows:
Quote:
8:21:24,882 INFO [STDOUT] Running Test 1
8:21:25,101 ERROR [STDERR] java.lang.ClassCastException
8:21:25,101 ERROR [STDERR] at net.sf.hibernate.type.SetType.wrap(SetType.ja
a:27)
8:21:25,101 ERROR [STDERR] at net.sf.hibernate.impl.SessionImpl.wrap(Sessio
Impl.java:2519)
8:21:25,288 ERROR [STDERR] at net.sf.hibernate.impl.SessionImpl.wrap(Sessio
Impl.java:2459)
8:21:25,288 ERROR [STDERR] at net.sf.hibernate.impl.SessionImpl.doSave(Sess
onImpl.java:708)
8:21:25,288 ERROR [STDERR] at net.sf.hibernate.impl.SessionImpl.save(Sessio
Impl.java:605)