-->
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.  [ 4 posts ] 
Author Message
 Post subject: How does CascadeType.Remove works?
PostPosted: Tue Nov 08, 2005 8:15 am 
Beginner
Beginner

Joined: Tue Aug 09, 2005 1:34 am
Posts: 26
Location: Bangalore
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0 beta 6

My Sql

The generated SQL (show_sql=true):2005-11-08 17:39:35,906 DEBUG com.spogger.services.impl.MediaServiceImpl - ### Exiting MediaServiceImpl.getMediaFileById(4). Return value was com.spogger.model.VideoFile@1bb3c06
2005-11-08 17:39:35,906 DEBUG com.spogger.helpers.ShowServiceServlet - MediaFile is com.spogger.model.VideoFile@1bb3c06
2005-11-08 17:39:35,906 DEBUG com.spogger.helpers.ShowServiceServlet - MediaFile Id is 4
2005-11-08 17:39:35,906 DEBUG com.spogger.services.impl.MediaServiceImpl - ### Entering MediaServiceImpl.deleteMediaFile(com.spogger.model.VideoFile@1bb3c06)
2005-11-08 17:39:35,906 DEBUG org.springframework.orm.hibernate3.SessionFactoryUtils - Opening Hibernate Session
2005-11-08 17:39:35,953 DEBUG org.hibernate.impl.SessionImpl - opened session at timestamp: 4634426474303488
2005-11-08 17:39:35,953 DEBUG org.hibernate.event.def.DefaultDeleteEventListener - deleting a transient instance
2005-11-08 17:39:35,953 DEBUG org.hibernate.event.def.DefaultDeleteEventListener - deleting [com.spogger.model.VideoFile#4]
2005-11-08 17:39:35,953 DEBUG org.hibernate.impl.SessionImpl - setting cache mode to: GET
2005-11-08 17:39:35,953 DEBUG org.hibernate.impl.SessionImpl - setting cache mode to: NORMAL
2005-11-08 17:39:35,953 DEBUG org.hibernate.impl.SessionImpl - setting cache mode to: GET
2005-11-08 17:39:35,953 DEBUG org.hibernate.impl.SessionImpl - setting cache mode to: NORMAL
2005-11-08 17:39:35,953 DEBUG org.springframework.orm.hibernate3.HibernateTemplate - Eagerly flushing Hibernate session
2005-11-08 17:39:35,953 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - flushing session
2005-11-08 17:39:35,953 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - processing flush-time cascades
2005-11-08 17:39:35,953 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - dirty checking collections
2005-11-08 17:39:35,953 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Flushing entities and processing referenced collections
2005-11-08 17:39:35,953 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Processing unreferenced collections
2005-11-08 17:39:35,953 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Scheduling collection removes/(re)creates/updates
2005-11-08 17:39:35,953 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Flushed: 0 insertions, 0 updates, 1 deletions to 1 objects
2005-11-08 17:39:35,953 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2005-11-08 17:39:36,015 DEBUG org.hibernate.pretty.Printer - listing entities:
2005-11-08 17:39:36,015 DEBUG org.hibernate.pretty.Printer - com.spogger.model.VideoFile{uniqueFileName=Unique, localPath=null, percentageCompletion=0, userId=1, actualEncodingTime=0, status=0, uploadDate=null, privacy=null, fileType=Video, fileName=
null, encodedFilePath=null, tags=bus,car,train,ship, estimatedEncodedTime=null, uploadDateString=null, iconFilePath=null, givenName=ManjithPic, fileId=4}
2005-11-08 17:39:36,015 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - executing flush
2005-11-08 17:39:36,015 DEBUG org.hibernate.persister.entity.BasicEntityPersister - Deleting entity: [com.spogger.model.VideoFile#4]
2005-11-08 17:39:36,015 DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2005-11-08 17:39:36,015 DEBUG org.hibernate.jdbc.ConnectionManager - opening JDBC connection
2005-11-08 17:39:36,015 DEBUG org.hibernate.SQL - delete from MEDIAFILE where FileId=?
Hibernate: delete from MEDIAFILE where FileId=?
2005-11-08 17:39:36,015 DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
2005-11-08 17:39:36,015 DEBUG org.hibernate.type.LongType - binding '4' to parameter: 1
2005-11-08 17:39:36,015 DEBUG org.hibernate.jdbc.AbstractBatcher - Adding to batch
2005-11-08 17:39:36,015 DEBUG org.hibernate.jdbc.AbstractBatcher - Executing batch size: 1
2005-11-08 17:39:36,015 DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2005-11-08 17:39:36,015 DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
2005-11-08 17:39:36,015 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - post flush
2005-11-08 17:39:36,062 DEBUG org.springframework.orm.hibernate3.SessionFactoryUtils - Closing Hibernate Session
2005-11-08 17:39:36,062 DEBUG org.hibernate.impl.SessionImpl - closing session
2005-11-08 17:39:36,062 DEBUG org.hibernate.jdbc.ConnectionManager - closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2005-11-08 17:39:36,062 DEBUG org.hibernate.jdbc.JDBCContext - after transaction completion
2005-11-08 17:39:36,062 DEBUG org.hibernate.impl.SessionImpl - after transaction completion
2005-11-08 17:39:36,062 DEBUG com.spogger.services.impl.MediaServiceImpl - ### Exiting MediaServiceImpl.deleteMediaFile(com.spogger.model.VideoFile@1bb3c06). Return value was void
2005-11-08 17:39:36,062 DEBUG com.spogger.helpers.ShowServiceServlet - deleteMediaFile Over..
2005-11-08 17:39:36,062 DEBUG com.spogger.helpers.ShowServiceServlet - setStreamToResponse() Exited...
2005-11-08 17:39:36,062 DEBUG com.spogger.helpers.ShowServiceServlet - setStreamToResponse Over...
2005-11-08 17:39:36,062 DEBUG com.spogger.helpers.ShowServiceServlet - doGet() Exited....



In my application I am using ManyToMany Mapping there is no problem with persisting the data in the AssociatedTable but there is a problem at the the time of deleting a record I have used CascadeType.Remove but this is not working...

Code:
package com.spogger.model;

import java.util.Set;

import javax.persistence.AssociationTable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity()
@org.hibernate.annotations.Proxy (lazy=false)
@Inheritance(
    discriminatorValue="VS"
)
public class VideoShow extends Show {
   
   Set <ImageFile> imageFiles;
   Set <VideoFile> videoFiles;
   
   
   public VideoShow() {
      
   }
   
   @ManyToMany(
         cascade={CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REMOVE},fetch=FetchType.EAGER
         )
   @AssociationTable(
         table=@Table(name="ShowAssets"),
         joinColumns = { @JoinColumn( name="showid") }
   )
   public Set<ImageFile> getImageFiles() {
      return imageFiles;
   }
   public void setImageFiles(Set <ImageFile> imageFiles) {
      this.imageFiles = imageFiles;
   }

   @ManyToMany(
         cascade={CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REMOVE},fetch=FetchType.EAGER
         )
   @AssociationTable(
         table=@Table(name="ShowAssets"),
         joinColumns = { @JoinColumn( name="showid") }
   )
   public Set<VideoFile> getVideoFiles() {
      return videoFiles;
   }

   public void setVideoFiles(Set<VideoFile> videoFiles) {
      this.videoFiles = videoFiles;
   }

}




Do I need to change anything in this code...
Can sbdy suggest me how to achieve the Delete from the Associated Table....


Thanks
Manjith Kumar.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 7:50 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
use the latest version of H Annotations.
do not use the same assoc table for 2 different associations
if the assoc are bidirectional, map one side a mappedBy="otherPropertySide"

_________________
Emmanuel


Top
 Profile  
 
 Post subject: JoinTable is causing some problems....
PostPosted: Wed Nov 09, 2005 8:32 am 
Beginner
Beginner

Joined: Tue Aug 09, 2005 1:34 am
Posts: 26
Location: Bangalore
Hi Emanuel,

Thanks For the reply.

I am using the latest version of Hibernate annotations 3.1 beta 6
I have an issue using JoinTable...
that is the reason I am using AssociationTable
moreover my implementation is Unidirectional.

Thanks
Manjith Kumar


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 8:58 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
@AssociationTable is completly ignored by the last version

_________________
Emmanuel


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