-->
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 @CollectionOfElements not deleting old value
PostPosted: Thu Jan 22, 2009 5:03 am 
Newbie

Joined: Thu Jan 22, 2009 4:35 am
Posts: 2
Hi All

I have the following problem:
I have a AdAction object which holds a set of AdActionParameter objects
The set of AdActionParameter is annotated in AdAction as @CollectionOfElements,
and the AdActionParameter class is annotated as @Embeddable

When I update the param value member of one of the AdActionParameter objects, the Hibernate generates the correct SQL statements:
delete AdActionParameter where param_value = old value
insert into AdActionParameter (param_value) values (new value)

The insert statement performed correctly, but for some reason the delete statement is not performed, and I get in the DB both the new and old rows.


Example of the hibernate generated statements:

/* delete collection row com.persistent.model.ad.AdAction.adActionParameters */ delete
from
AD_ACTION_PARAMETER
where
AD_ACTION_ID=?
and AD_ACTION_PARAMETER_NAME=?
and PARAM_VALUE=?
and RESOURCE_ID=?
DEBUG btpool0-2 org.hibernate.type.LongType - binding '50366255' to parameter: 1
DEBUG btpool0-2 org.hibernate.type.StringType - binding '8888888888888' to parameter: 3
DEBUG btpool0-2 org.hibernate.type.LongType - binding null to parameter: 4
DEBUG btpool0-2 org.hibernate.SQL -
/* insert collection
row com.persistent.model.ad.AdAction.adActionParameters */ insert
into
AD_ACTION_PARAMETER
(AD_ACTION_ID, AD_ACTION_PARAMETER_NAME, PARAM_VALUE, RESOURCE_ID)
values
(?, ?, ?, ?)
DEBUG btpool0-2 org.hibernate.type.LongType - binding '50366255' to parameter: 1
DEBUG btpool0-2 org.hibernate.type.StringType - binding '99999999999' to parameter: 3
DEBUG btpool0-2 org.hibernate.type.LongType - binding null to parameter: 4


When I copy&paste the deletes statement to sql plus it delete the row, so the delete statement is correct, but for some reason is not performed

The code of the 2 mapped classes (with omitting some members for clarity):


Code:
@Entity
@Table(name="AD_ACTION")
public class AdAction extends PersistentEntity {
   
     private long adActionID;

    @Id
    @Column(name = "AD_ACTION_ID")
    @SequenceGenerator(name = "s1", sequenceName = "CMS_SEQUENCE")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "s1")
   public long getAdActionID() {
      return adActionID;
   }
   public void setAdActionID(long adActionID) {
      this.adActionID = adActionID;
   }
   
   private Set<AdActionParameter> adActionParameters = new HashSet<AdActionParameter>();
   
   @CollectionOfElements
   @Fetch(FetchMode.JOIN)
   @JoinTable(name = "AD_ACTION_PARAMETER", joinColumns = @JoinColumn(name = "AD_ACTION_ID"))
   public Set<AdActionParameter> getAdActionParameters() {
      return adActionParameters;
   }
   public void setAdActionParameters(Set<AdActionParameter> adActionParameters) {
      this.adActionParameters = adActionParameters;
   }
   
}


@Embeddable
public class AdActionParameter extends PersistentEntity {
   
   private String paramValue;
   
   @Column(name="PARAM_VALUE")
   public String getParamValue() {
      return paramValue;
   }
   public void setParamValue(String paramValue) {
      this.paramValue = paramValue;
   }
   
   
   @Override
   public int hashCode() {
      ......
   }
   
   @Override
   public boolean equals(Object obj) {
           .....
   }   
}
   


Thanks,
Alon


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.