Hello,
I have two Hibernate classes that represent a ManyToMany relational mapping between two tables (BildeAlbum and Bilde), with the joining table BildeAlbumBilde, which is basically for picture within albums. I want to create Sets, so that a single picture (Bilde) can exists in multiple albums, and vice versa.
I have gotten the mapping correct, and if I use CascadeType.ALL, I can retreive the data successfully from the database.
However, when I delete an album, I want the albums references in the linking table (BildeAlbumBilde) to be removed, but I do NOT want the picture from the Bilde table to be removed at all. Similarly for Pictures. Deleting a picture will remove it from the linking table and the picture table, but NOT from the album table.
I have tried a number of different settings, but if I do not have CascadeType.ALL I get the following error when I attempt to retrieve and view the PictureAlbum and its Pictures:
Code:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: info.devsiden.dsj.persistancetier.data.BildeData
org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)
org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)
org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:78)
org.hibernate.persister.collection.AbstractCollectionPersister.writeElement(AbstractCollectionPersister.java:755)
...