-->
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: one to many mapping using annotations issues
PostPosted: Wed May 26, 2010 4:39 am 
Newbie

Joined: Wed May 19, 2010 6:03 am
Posts: 19
Hi All,

I have two table USER and ADDRESS. A user may have more than one address.
I have two address for one user

Code:
@Entity
@Table(name = "USER", uniqueConstraints = { @UniqueConstraint(columnNames = { "user_id" }) })
public class UserDO {
   @Id
   @Column(name = "user_id", columnDefinition = "VARCHAR(255) NOT NULL DEFAULT ''", insertable = true)
   private String userId;

@OneToMany(cascade= CascadeType.ALL, mappedBy="userDO", fetch = FetchType.LAZY)
    private Set<AddressDO> userAddress;

public String getUserId() {
      return userId;
   }

   public void setUserId(String userId) {
      this.userId = userId;
   }

public Set<AddressDO> getUserAdrress() {
      return this.userAddress;
   }

   public void setUserAdrress(Set<AddressDO> userAddress) {
      this.userAddress = userAddress;
   }
}


Code:
@Entity
@Table(name = "ADDRESS",uniqueConstraints = {
      @UniqueConstraint(columnNames={"address_id"})}
)
public class AddressDO {

   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "address_id", insertable = true)
   private long  address_id;     

@ManyToOne
   @org.hibernate.annotations.Cascade(value = { org.hibernate.annotations.CascadeType.SAVE_UPDATE })
   @JoinColumn(name="user_id")   
   private UserDO userDO;

public long getAddress_id() {
      return address_id;
   }

   public void setAddress_id(long address_id) {
      this.address_id = address_id;
   }

public UserDO getUserDO() {
      return userDO;
   }

   public void setUserDO(UserDO userDO) {
      this.userDO = userDO;
   }

}


This is working fine for insert operation in session.save(userDo);
But for session.update(userDo); instead of updating the address table it is inserting again.
For delete also the USER table got deleted but not from ADDRESS table

Any Idea?


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.