-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: parent key not found Exception
PostPosted: Fri Sep 21, 2007 4:25 am 
Newbie

Joined: Mon Aug 13, 2007 6:38 am
Posts: 16
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 21, 2007 10:46 am 
Newbie

Joined: Fri Sep 21, 2007 3:32 am
Posts: 6
please add ADDRESS mapping


Top
 Profile  
 
 Post subject: need to provide inverse=true
PostPosted: Tue Sep 25, 2007 3:18 pm 
Newbie

Joined: Tue Sep 18, 2007 11:13 am
Posts: 8
u need to provide the attribute inverse=true for many-to-one on addresses.
else save the address first with a session.flush() and the save the contact.

hope this works.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.