Hi,
This is the first time iam working with Hibernate and iam facing some problems. When iam implementing parent-child relationship a row in the parent table gets created but it does not create it in the child table. What happens is that an Hibernate exception is thrown Hibernate Exception SQL update or deletion failed (row not found). It is not attempting to create the new child record rather it is trying to update the child record which iam not able to understand. Iam using the generator class="assigned" for Id. Please help me out. I have spent lot of time to debug the problem but in vain.
The logs:
Hibernate: insert into event (title, hostname, hostid, location, contact_phone,
eventDate, description, img_filename, eventid) values (?, ?, ?, ?, ?, ?, ?, ?, ?
)
Hibernate: update invitee set eventid=?, i_firstname=?, i_lastname=?, status=? w
here i_emailid=?
Hibernate ExceptionSQL update or deletion failed (row not found)
Event.hbm.xml
-------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.eforce.eInvitation.Event" table="event" >
<id name="eventId" column="eventid" unsaved-value="null">
<generator class="assigned"/>
</id>
<property name="title" column="title" type="java.lang.String" />
<property name="hostName" column="hostname" type="java.lang.String" />
<property name="hostId" column="hostid" type="java.lang.String" />
<property name="location" column="location" type="java.lang.String" />
<property name="contactphone" column="contact_phone" type="java.lang.String" />
<property name="eventDate" column="eventDate" type="java.lang.String" />
<property name="description" column="description" type="java.lang.String" />
<property name="img_filename" column="img_filename" type="java.lang.String" />
<set name="invitees" cascade="all">
<key column="eventid" />
<one-to-many class="com.eforce.eInvitation.Invitee" />
</set>
</class>
</hibernate-mapping>
public class Event implements Serializable {
private String eventId= null;
private String title = null;
private String hostId = null;
private String hostName = null;
private String location=null;
private String contactphone=null;
private String eventDate=null;
private String description=null;
private String img_filename=null;
private Set invitees = null;
public String getEventId()
{
return this.eventId;
}
public String getTitle()
{
return this.title;
}
public String getHostId()
{
return this.hostId;
}
public String getHostName()
{
return this.hostName;
}
public String getLocation()
{
return this.location;
}
public String getContactphone()
{
return this.contactphone;
}
public String getEventDate()
{
return this.eventDate;
}
public String getDescription()
{
return this.description;
}
public String getImg_filename()
{
return this.img_filename;
}
public Set getInvitees() {
return this.invitees;
}
public void setEventId(String eventId)
{
this.eventId = eventId;
}
public void setTitle(String title)
{
this.title = title;
}
public void setHostId(String hostId)
{
this.hostId = hostId;
}
public void setHostName(String hostName)
{
this.hostName = hostName;
}
public void setLocation(String location)
{
this.location = location;
}
public void setContactphone(String contactphone)
{
this.contactphone = contactphone;
}
public void setEventDate(String eventDate)
{
this.eventDate = eventDate;
}
public void setDescription(String description)
{
this.description = description;
}
public void setImg_filename(String img_filename)
{
this.img_filename = img_filename;
}
public void setInvitees(Set invitees) {
this.invitees = invitees;
}
}
Invitee.hbm.xml
---------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.eforce.eInvitation.Invitee" table="invitee" >
<id name="i_emailId" column="i_emailid" unsaved-value="any">
<generator class="assigned"/>
</id>
<property name="eventId" column="eventid" type="java.lang.String" />
<property name="i_firstname" column="i_firstname" type="java.lang.String" />
<property name="i_lastname" column="i_lastname" type="java.lang.String" />
<property name="status" column="status" type="java.lang.String" />
</class>
</hibernate-mapping>
package com.eforce.eInvitation;
import java.io.Serializable;
import com.eforce.eInvitation.Event;
public class Invitee implements Serializable{
private String i_emailId = null;
private String eventId = null;
private String i_firstname = null;
private String i_lastname = null;
private String status = null;
private Event parent = null;
public Event getParent()
{
return this.parent;
}
public void setParent(Event parent)
{
this.parent = parent;
}
public String getI_emailId()
{
return this.i_emailId;
}
public String getEventId()
{
return this.eventId;
}
public String getI_firstname()
{
return this.i_firstname;
}
public String getI_lastname()
{
return this.i_lastname;
}
public String getStatus()
{
return this.status;
}
public void setI_emailId(String i_emailId)
{
this.i_emailId = i_emailId;
}
public void setEventId(String eventId)
{
this.eventId = eventId;
}
public void setI_firstname(String i_firstname)
{
this.i_firstname = i_firstname;
}
public void setI_lastname(String i_lastname)
{
this.i_lastname = i_lastname;
}
public void setStatus(String status)
{
this.status = status;
}
}
Service class
-------------
public void createEvent(CreateEventVO eventVO)
{
Session session = ConnectionFactory.getInstance().getSession();
try
{
guid = new GUID().toString();
System.out.println("New GUID : " + guid);
Transaction t = session.beginTransaction();
session.save(getEvent(eventVO));
t.commit();
}
catch (HibernateException e)
{
System.err.println("Hibernate Exception" + e.getMessage());
//throw new RuntimeException(e);
}
finally
{
if (session != null)
{
try
{
session.close();
}
catch (HibernateException e)
{
System.err.println("Hibernate Exception" + e.getMessage());
throw new RuntimeException(e);
}
}
}
}
public Event getEvent(CreateEventVO eventVO){
this.eventVO = eventVO;
event = new Event();
System.out.println("value of eventid " + guid);
event.setEventId(guid);
event.setTitle(eventVO.getTitle());
event.setHostName(eventVO.getHostName());
event.setHostId(eventVO.getHostId());
event.setLocation(eventVO.getLocation());
event.setContactphone(eventVO.getPhone());
event.setEventDate(eventVO.getDateTime());
event.setDescription(eventVO.getDescription());
event.setImg_filename(eventVO.getGraphics());
Set invitees = new HashSet();
Invitee invitee = null;
System.out.println("value of emain AList : "+ eventVO.getInviteeList().size());
if(eventVO.getInviteeList().size() > 0)
{
ArrayList emailId = (ArrayList)eventVO.getInviteeList();
for(int i = 0; i < eventVO.getInviteeList().size(); i++)
{
invitee = new Invitee();
invitee.setI_emailId(emailId.get(i).toString());
System.out.println("invitee.getI_emailId : "+ emailId.get(i).toString());
invitee.setEventId(guid);
invitees.add(invitee);
}
System.out.println("invitee size : "+ invitees.size());
}
event.setInvitees(invitees);
return event;
}[code][/code]
|