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
|