-->
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: cascade save is not happening.
PostPosted: Fri May 21, 2010 4:10 pm 
Newbie

Joined: Wed Jan 20, 2010 11:12 am
Posts: 15
I have two tables
packet and packet_notes
packet table is having pk_packet_id as its primary key, autoincrement
packet notes table is having a foreign key fk_packet_id referencing to pk_packet_id of packet table.

Now I have made two Models for these tables Say Packet.java and PacketNotes.java
in PacketNotes hbm file i have a mapping like
Code:
<many-to-one class="Packet" fetch="select" name="packet"  foreign-key="fk_packet_id_relation3" cascade="save-update">
            <column name="fk_packet_id"/>
</many-to-one>

and its very Obvious that I have a setter and getter for that in PacketNotes.java file like
Code:
setPacket(Packet packetObj)
getPacket()


Now what I am thinking is
Suppose both the tables are blank...
then if I do like this
Code:
Packet p = new Packet();
//not setting any primary key value here
p.setPacketName("first");

PacketNotes notes = New PacketNotes();
notes.setPacketNoteName("first packet note");
notes.setPacket(p);


and if i try to save this notes object like: save(notes);
then what i am thinking is ?
1. packet saved first and an pk_packet_id value will be 1,
2. insert will happen on notes and the Id of packet(1) is assigned automatically to fk_packet_id?
please clear my doubt as it is not happening, and its giving me error like
can't update or add child foreign key contraint fails.


Top
 Profile  
 
 Post subject: Re: cascade save is not happening.
PostPosted: Sat May 22, 2010 2:41 pm 
Newbie

Joined: Wed Jan 20, 2010 11:12 am
Posts: 15
If My thinking is wrong than u guys can correct me... but atleast some reply i am expecting.

Can't we do that?


Top
 Profile  
 
 Post subject: Re: cascade save is not happening.
PostPosted: Mon May 24, 2010 4:38 am 
Newbie

Joined: Wed Jan 20, 2010 11:12 am
Posts: 15
thank you guys...
I had solved it.


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.