-->
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.  [ 7 posts ] 
Author Message
 Post subject: Problems with Cascade="all" on parent map.....
PostPosted: Thu Mar 18, 2004 6:57 am 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
Hi,
I have 2 maps. On the child map I have a foreign key generator and a one to one relationship on the parent. This works fine. If I add a new parent, the generated key of the parent is written to the child as well. I then added a cascade="all" to the one to one relationship of the child map, and when i delete a child it deletes the parent, fine, which is not what I want in the real world but I did it just to see how the cascade worked in practice. I then added a one to one relationship to the parent map and set cacade="all' also setting cascade="none" on the child map, and now when I try to delete a parent so that it deletes the child record as well, nothing happens. The parent map has a generated ID. What am I doing wrong?

Parent:
<hibernate-mapping package="test">
<class name="Artist" table="artisttbl">
<id name="ID" column="artist_id">
<generator class="sequence">
<param name="sequence">artist_seq_id</param>
</generator>
</id>
<property name="ArtistName" column="artist_name" type="string" not-null="true"/>
<property name="ArtistInfo" column="artist_info" type="string" not-null="true"/>
<property name="TrackLocation" column="track_location" type="string"/>
<property name="TrackInfo" column="track_info" type="string"/>

<one-to-one name="artistimages" class="ArtistImages" cascade="all"/>
</class>
</hibernate-mapping>

Parent:Class:Snippet

private ArtistImages artistimages;


public ArtistImages getArtistImages(){
return artistimages;
}

public void setArtistImages(ArtistImages newArtistImages){
this.artistimages = newArtistImages;
}

child:
<hibernate-mapping package="test">
<class name="ArtistImages" table="artistimagestbl">
<id name="ID" column="artist_id">
<generator class="foreign">
<param name="property">artist</param>
</generator>
</id>
<property name="ArtistPhoto1" column="artist_photo1" type="binary"/>
<property name="ArtistPhoto2" column="artist_photo2" type="binary"/>
<property name="ArtistPhoto3" column="artist_photo3" type="binary"/>

<one-to-one name="artist" class="Artist" constrained="true" cascade="none"/>
</class>
</hibernate-mapping>

Child:Class:Snippet

private Artist artist;

public Artist getArtist(){
return artist;
}

public void setArtist(Artist newArtist){
this.artist = newArtist;
}

many thanks in advance


Top
 Profile  
 
 Post subject: Ok chaps, i'm well and truely stuck...
PostPosted: Thu Mar 18, 2004 3:11 pm 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
I am trying to create a Bidirectional link between 2 maps, Artist and ArtistImages. On creating an Artist record an associated Artistimages record is created as well with the ArtistImages being assigned a primarykey from the generated key created in Artist. can anybody please tell me what looks wrong with my map definitions as no records are being written to either table unless i comment out '<one-to-one..../>' in the Artist map.

Artsist: parent map -:

<hibernate-mapping package="test">
<class name="Artist" table="artisttbl">
<id name="ID" column="artist_id">
<generator class="sequence">
<param name="sequence">artist_seq_id</param>
</generator>
</id>
<property name="ArtistName" column="artist_name" type="string" not-null="true"/>
<property name="ArtistInfo" column="artist_info" type="string" not-null="true"/>
<property name="TrackLocation" column="track_location" type="string"/>
<property name="TrackInfo" column="track_info" type="string"/>
<one-to-one name="artistimages"
class="ArtistImages"/>
</class>
</hibernate-mapping>

Artist: class : snippet -:

public class Artist implements Serializable{

..... other defs...........
private ArtistImages artistimages;

public Artist(){
}

public ArtistImages getArtistImages(){
return artistimages;
}

public void setArtistImages(ArtistImages newArtistImages){
this.artistimages = newArtistImages;
}
............

ArtsistImages: child map -:

<hibernate-mapping package="test">
<class name="ArtistImages" table="artistimagestbl">
<id name="ID" column="artist_id">
<generator class="foreign">
<param name="property">artist</param>
</generator>
</id>
<property name="ArtistPhoto1" column="artist_photo1" type="binary"/>
<property name="ArtistPhoto2" column="artist_photo2" type="binary"/>
<property name="ArtistPhoto3" column="artist_photo3" type="binary"/>
<one-to-one name="artist"
class="Artist"
constrained="true"/>
</class>
</hibernate-mapping>

ArtistImages: class : snippet -:

public class ArtistImages implements Serializable{

..... other defs ......
private Artist artist;

public ArtistImages(){
}

public Artist getArtist(){
return artist;
}

public void setArtist(Artist newArtist){
this.artist = newArtist;
}
..........


many thanks in advance


Top
 Profile  
 
 Post subject: I must
PostPosted: Thu Mar 18, 2004 3:53 pm 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
mention that the one-to-one relationship statement in Artist should read as:

<one-to-one name="artistimages" class="ArtistImages" cascade="all"/>.

So just to recap, I want to be able to:

1. Add an Artist record and an associated Artistimages record to their respective tables, ensuring that the artistimages record shares the same ID as the Artist record. This is acheived with the one-to-one statement as well as the foreign generator in the ArtistImages map.

2. On deleting an Artist record, also delete the associated ArtistImages record which shares the same primary key as the Artist record. This should be the case with the inclusion of the one-to-one statement in the Artist map, but nothing works when I add this line. No records can be added and no records can be deleted. HELP!!!!!!!

many thanks in advance


Top
 Profile  
 
 Post subject: Please...
PostPosted: Thu Mar 18, 2004 6:47 pm 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
inform me if this question requires further information to be properly answered....???


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 19, 2004 5:58 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Did you set both side of the association in your Java code before saveOfUpdate() call ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject: All...
PostPosted: Fri Mar 19, 2004 12:21 pm 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
has been resolved now. Thanks for your help.

Peter


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 12:36 am 
Newbie

Joined: Mon Apr 05, 2004 2:50 am
Posts: 17
Hello dukeswharf,

How have you resolved your one-to-one problem. I have got the same problem and interesting to your soution thank you.


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