Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3
Mapping documents:
<hibernate-mapping package="com.cl.pojo">
<class name="Contact" table="CONTACT">
<id name="id" type="long" column="ID" >
<generator class="increment"/>
</id>
<many-to-one name="address" class="com.cl.pojo.Address" fetch="select" cascade="all">
<column name="address_id"/>
</many-to-one>
<set name="subject" cascade="all">
<key column="subject_id"/>
<one-to-many class="Subjects"/>
</set>
<property name="firstName">
<column name="FIRSTNAME" />
</property>
<property name="lastName">
<column name="LASTNAME"/>
</property>
<property name="email">
<column name="EMAIL"/>
</property>
</class>
</hibernate-mapping>
Full stack trace of any exception that occurs:
Hibernate: /* insert com.cl.pojo.Address */ insert into ADDRESS (STD_ID, CITY, P
HONE, ID) values (?, ?, ?, ?)
Hibernate: /* insert com.cl.pojo.Contact */ insert into CONTACT (address_id, FIR
STNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?, ?)
[13:53:41.125] SQL Error: 2291, SQLState: 23000
[13:53:41.125] ORA-02291: integrity constraint (ERP.FK6382B000AFE1B37D) violated
- parent key not found
[13:53:41.125]
[13:53:41.125] SQL Error: 2291, SQLState: 23000
[13:53:41.125] ORA-02291: integrity constraint (ERP.FK6382B000AFE1B37D) violated
- parent key not found
[13:53:41.125]
[13:53:41.125] Could not synchronize database state with session
[13:53:41.125] org.hibernate.exception.ConstraintViolationException: Could not e
xecute JDBC batch update
[13:53:41.125] at org.hibernate.exception.SQLStateConverter.convert(SQLStateCon
verter.java:71)
[13:53:41.125] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExcep
tionHelper.java:43)
[13:53:41.125] at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatch
er.java:202)
[13:53:41.125] at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractB
atcher.java:91)
[13:53:41.125] at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractB
atcher.java:86)
[13:53:41.125] at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(Abst
ractBatcher.java:171)
[13:53:41.125] at org.hibernate.persister.entity.AbstractEntityPersister.insert
(AbstractEntityPersister.java:2048)
Name and version of the database you are using:10g
Now my class for contact is :-
package com.cl.pojo;
import java.io.Serializable;
import java.util.*;
public class Contact implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private long id;
private String firstName;
private String lastName;
private String email;
private Address address;
private Set subject;
public Contact()
{ }
public Contact(Address address,Set subject,String firstName,String lastName,String email)
{
this.address = address;
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.subject = subject;
}
public Address getAddress() {
return this.address;
}
public void setAddress(Address address) {
this.address = address;
}
public Set getSubject() {
return this.subject;
}
public void setSubject(Set subject) {
this.subject = subject;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
Now when I write a code shown below in jsp , its shows an exception---
SessionFactory sessionFactory = HibernateUtility.getSessionFactory();
session1 = sessionFactory.openSession();
transaction = session1.beginTransaction();
Subjects sub1 = new Subjects(sub[0]);
Subjects sub2 = new Subjects(sub[1]);
//session1.save(address);
//transaction.commit();
contact.setAddress(address);
Set set = new HashSet();
set.add(sub1);
set.add(sub2);
contact.setSubject(set);
//session1.save(set);
session1.save(contact);
transaction.commit();
Now why this error is occuring,Please help....
Regards,
Abhishek