-->
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: Updating multiple tables
PostPosted: Tue Jun 17, 2014 1:37 pm 
Newbie

Joined: Tue Mar 22, 2011 10:44 am
Posts: 11
Hi All,

I have entities like below

Code:
@Entity
@SecondaryTable(name = "CLM", pkJoinColumns = @PrimaryKeyJoinColumn(name = "event_id", referencedColumnName = "event_id"))
public class Claim extends Event {
        private Date lossDate;
        private Set<ClaimDetail> claimDetails;

        @Column(table="CLM", name="clm_loss_date")
   public Date getLossDate() {
      return lossDate;
   }
   public void setLossDate(Date lossDate) {
      this.lossDate = lossDate;
   }

        @OneToMany(cascade = CascadeType.ALL, orphanRemoval=true, mappedBy="parentClaim")
   public Set<ClaimDetail> getClaimDetails() {
      return claimDetails;
   }
   public void setClaimDetails(Set<ClaimDetail> claimDetails) {
      this.claimDetails = claimDetails;
   }


Code:
@Entity
@Table(name="CLM_DTL")
public class ClaimDetail extends DomainObject{
        private ClaimDetailPk id;
        private Float billHours;
   private Double amount;

        @EmbeddedId
   public ClaimDetailPk getId() {
      return id;
   }
   public void setId(ClaimDetailPk id) {
      this.id = id;
   }
       @Column(name="clm_dtl_bill_hrs")
   public Float getBillHours() {
      return billHours;
   }
   public void setBillHours(Float billHours) {
      this.billHours = billHours;
   }
   @Column(name="clm_dtl_amt")
   public Double getAmount() {
      return amount;
   }
   public void setAmount(Double amount) {
      this.amount = amount;
   }

        @Embeddable
   @SuppressWarnings("PMD")
   public static class ClaimDetailPk implements Serializable {      
      private Long eventId;   
      
      @Column(name="event_id")
      public Long getEventId() {
         return eventId;
      }
      public void setEventId(Long eventId) {
         this.eventId = eventId;
      }
      
      @Override
      public int hashCode() {
         ....................
      }
      @Override
      public boolean equals(Object obj) {
         .........................
      }         
   }


And my table looks like this
Code:
CLM
----
EVENT_ID
CLM_LOSS_DATE


Code:
CLM_DTL
--------
EVENT_ID
CLM_DTL_AMT
CLM_DTL_BILL_HRS


Now I have to update losss_date, amt and hours. For this do i have to write two different update statements to update CLM and CLM_DTL table or is there a way to do with single update in Hibernate?


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.