-->
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.  [ 2 posts ] 
Author Message
 Post subject: AnnotatedClasses - Deletion Operation
PostPosted: Wed Aug 17, 2011 11:15 pm 
Newbie

Joined: Wed Aug 17, 2011 9:30 pm
Posts: 2
Hie all, I'm quite new with Hibernate. I'm currently using Hibernate 3.4 and having a problem to perform deletion operation to a persistance object in my project implementing SPRING, Hibernate & Tiles togather.

I have an object BlogEntry that has 2-manytoone relationship with object Company and BlogEntryStatus as below:

Code:

package KSA.object;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name="BlogEntry")
public class BlogEntry implements Serializable {

   /**
    *
    */
   private static final long serialVersionUID = 1L;
   private long blogEntryId;
   private String title;
   private String entryBody;
   private User postedBy;
   private Date postedDate;
   
   private Company company;
   private BlogEntryStatus blogEntryStatus;
   
   
   @Id
   @GeneratedValue
   @Column(name="blogEntryId")
   public long getBlogEntryId() {
      return blogEntryId;
   }
   public void setBlogEntryId(long blogEntryId) {
      this.blogEntryId = blogEntryId;
   }
   @Column(name="title")
   public String getTitle() {
      return title;
   }
   public void setTitle(String title) {
      this.title = title;
   }
   @Column(name="entryBody")
   public String getEntryBody() {
      return entryBody;
   }
   public void setEntryBody(String entryBody) {
      this.entryBody = entryBody;
   }
   @Column(name="postedDate")
   public Date getPostedDate() {
      return postedDate;
   }
   public void setPostedDate(Date postedDate) {
      this.postedDate = postedDate;
   }
   @ManyToOne(cascade = CascadeType.ALL)
   @JoinColumn(name = "userId")
   public User getPostedBy() {
      return postedBy;
   }
   public void setPostedBy(User postedBy) {
      this.postedBy = postedBy;
   }
   @ManyToOne(cascade = CascadeType.ALL)
   @JoinColumn(name = "companyId")
   public Company getCompany() {
      return company;
   }
   public void setCompany(Company company) {
      this.company = company;
   }
   
   @ManyToOne(cascade = CascadeType.ALL)
   @JoinColumn(name = "statusId")
   public BlogEntryStatus getBlogEntryStatus() {
      return blogEntryStatus;
   }
   public void setBlogEntryStatus(BlogEntryStatus blogEntryStatus) {
      this.blogEntryStatus = blogEntryStatus;
   }
         
}


When I click delete, the controller passed the instruction to the DAO to execute deletion operation of object BlogEntry through its Id as below:

Controller's:
Code:
@RequestMapping("/blog/deleteBlogEntry")
   public ModelAndView deleteBlogEntry(HttpServletRequest request)
   {
      BlogEntry blogEntry = blogEntryDAO.getBlogEntry(Long.parseLong(request.getParameter("blogEntryId")));
      
      blogEntryDAO.deleteBlogEntry(blogEntry);
      
      return new ModelAndView("redirect:../landingPage.html");
   }



DAO implementation:
Code:
@Override
   public boolean deleteBlogEntry(BlogEntry blogEntry) {
      // TODO Auto-generated method stub
      
      boolean blogEntryDeleted = false;
            
      ht.delete(blogEntry);
      ht.flush();
      blogEntryDeleted = true;
      
      return blogEntryDeleted;
   }


The operation however delete other data on other tables that are not related to BlogEntry object. Where my mistake is??? Can somebody show me the correct method to do deletion operation in Hibernate???

Thanks


Top
 Profile  
 
 Post subject: Re: AnnotatedClasses - Deletion Operation
PostPosted: Thu Aug 18, 2011 3:58 am 
Newbie

Joined: Wed Aug 17, 2011 9:30 pm
Posts: 2
Can anyone help me? It has been a few days that I cannot find the solution or why it happens that way...

Thanks.


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