-->
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.  [ 2 posts ] 
Author Message
 Post subject: Foriegn Key References Chapter one
PostPosted: Sun May 18, 2008 8:30 am 
Newbie

Joined: Sun May 18, 2008 8:21 am
Posts: 1
The colume nextMessage is foregin key references id and this has casecade as all.

If i delete one message than all the references should be deleated. But this is not happening.



<many-to-one
name="nextMessage"
cascade="all"
column="NEXT_MESSAGE_ID"
foreign-key="FK_NEXT_MESSAGE"/>

Example
-------------------------
// ############################################################################

// First unit of work
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();

Message parent = new Message("Parent");
parent.setText("I am Parent");
Message child1 = new Message("child1");
child1.setText("I am child1");
Message child2 = new Message("child2");
child2.setText("I am child2");

parent.setNextMessage(child1);
child1.setNextMessage(child2);

session.save(parent);
tx.commit();
session.close();

// Shutting down the application
HibernateUtil.shutdown();
}


-----------------------------------------------------

If I delete the parent. Than all the childs should go. because they have foreign key references

But this is not happening. Any clue?

Thanks in Advance
Balaji


Top
 Profile  
 
 Post subject: cascade all
PostPosted: Thu May 22, 2008 7:32 am 
Newbie

Joined: Thu May 22, 2008 6:45 am
Posts: 2
Location: Bangalore
Hi Balaji,

You are defining cascade=all in wrong place.
If you are deleting the record in the main table that is the talbe
where NEXT_MESSAGE is primary key.
There you might have defined one-to-many there you need to specify this attribute then it will work proper i hope.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.