Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.hibernate.DuplicateMappingException: Table contains physical column name [coverage_name] referred to by multiple physical column names:

I am using below class but giving the exception like Caused by: org.hibernate.DuplicateMappingException: Table [] contains physical column name [scheme_name] referred to by multiple physical column names: [SCHEME], [schemeName] help me to solve this issue.

@Embeddable
public class DRollSchemesId implements Serializable{

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "ROLL_NO", length = 20)
    private String rollNo;

    @Id
    @Column(name = "SCHEME", length = 100, updatable = false, insertable = false )
    private String schemeName;

   public DRollSchemesId() {
   }

   public DRollSchemesId(String rollNo, String schemeName) {
      this.rollNo = rollNo;
      this.schemeName = schemeName;
   }

   public String getrollNo() {
       return this.rollNo;
   }

   public void setrollNo(String rollNo) {
       this.rollNo = rollNo;
   }
   public String getschemeName() {
       return this.schemeName;
   }

   public void setschemeName(String schemeName) {
       this.schemeName = schemeName;
   }

This is entity here i am trying to use composite key by using that Embeddable class.

@Entity
@Table(name = "D_ROLL_SCHEMES")
  @IdClass(DRollSchemesId.class)
public class DRenewalAddonCoverages  implements java.io.Serializable{

  private static final long serialVersionUID = 1L;

  private DRollSchemesId id;
  @Id
  @Column(name = "ROLL_NO", length = 20)
    private String rollNo;

  @Id
  @Column(name = "SCHEME", length = 100, updatable = true, insertable 
= true )
    private String schemeName;



    public DRenewalAddonCoverages(){
    }


  @Id
  @AttributeOverrides(
      {
        @AttributeOverride(column = @Column(name = "ROLL_NO",  
updatable = true, insertable = true), name = "rollNo"),
        @AttributeOverride(column = @Column(name = "SCHEME", updatable 
= true, insertable = true), name = "schemeName")

      })

  @EmbeddedId
  public DRollSchemesId getId() {
        return this.id;
    }


    public String getrollNo() {
    return rollNo;
  }


  public void setrollNo(String rollNo) {
    this.rollNo = rollNo;
  }


  public String getschemeName() {
    return schemeName;
  }

  public void setschemeName(String schemeName) {
    this.schemeName = schemeName;
  }


  public void setId(DRollSchemesId id) {
        this.id = id;
    }

}
like image 743
Roshini Avatar asked Nov 08 '22 03:11

Roshini


1 Answers

Try as below:

class DRollSchemesId implements Serializable {
    private String rollNo;
    private String schemeName;
}

@Entity
@Table(name = "D_ROLL_SCHEMES")
@IdClass(DRollSchemesId.class)
public class DRenewalAddonCoverages implements java.io.Serializable {

    @Id
    @Column(name = "ROLL_NO", length = 20)
    private String rollNo;

    @Id
    @Column(name = "SCHEME", length = 100, updatable = true, insertable = true)
    private String schemeName;

}
like image 63
Zi WANG Avatar answered Nov 14 '22 22:11

Zi WANG