-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate one-to-many mapping not working
PostPosted: Sun Jul 08, 2012 3:05 am 
Newbie

Joined: Sun Jul 08, 2012 2:28 am
Posts: 2
Hi,

I am new to Hibernate. I am facing issue mapping related issue. Following are the details.

I have scenario where evtEvent entity is related to edocEventDocument entity such that one evtEvent can have many edocEventDocument.

My problem is that, when I add new object into collection and then call save method of evtEvent object then that new objects are inserted accordingly in edocEventDocment table. but when I remove few object from document collection then accordingly that rows are not deleted from edocEventDocument table.

Can anyone please help me to understand what I am doing wrong?

Following is the table structure.
evt_event(
evt_code (primary key)
)

edoc_evt_document(
edoc_version,
edoc_evt_code( foreign key from event table)
)

Following is the Event entity
Code:
@Entity
@Table(name = "evt_event", schema="tmpdev")
public class EvtEvent  implements java.io.Serializable {
     private String evtCode;
      private Set<EdocEvtDocument> edocEvtDocuments = new HashSet<EdocEvtDocument>(0);
    @Id
   
    @Column(name="evt_code", unique=true, nullable=false, length=20)

    public String getEvtCode() {
        return this.evtCode;
    }
   
    public void setEvtCode(String evtCode) {
        this.evtCode = evtCode;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="evtEvent")

    public Set<EdocEvtDocument> getEdocEvtDocuments() {
        return this.edocEvtDocuments;
    }
   
    public void setEdocEvtDocuments(Set<EdocEvtDocument> edocEvtDocuments) {
        this.edocEvtDocuments = edocEvtDocuments;
    }
}


Following is the EdocEvtDocument
Code:
@Entity
@Table(name = "edoc_evt_document", schema = "tmpdev")
public class EdocEvtDocument implements java.io.Serializable {
   private Integer edocVersion;
   private EvtEvent evtEvent;

      
   @Id
   @Column(name = "edoc_version", unique = true, nullable = false)
   public Integer getEdocVersion() {
      return this.edocVersion;
   }

   public void setEdocVersion(Integer edocVersion) {
      this.edocVersion = edocVersion;
   }

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "edoc_evt_code", nullable = false)
   public EvtEvent getEvtEvent() {
      return this.evtEvent;
   }

   public void setEvtEvent(EvtEvent evtEvent) {
      this.evtEvent = evtEvent;
   }



Thanks,
Rohit


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.