org.hibernate.HibernateException:“ Abc”实例的标识符从“ abc”更改为“ def”

时间:2018-12-04 12:54:51

标签: spring hibernate spring-boot spring-batch

更新春季批处理时出现此错误。

这是我的实体表。

@Entity

public class Abc {
@Column(name = Reference_Number, length = 16)
private UUID referenceNumber;

@Column(name = ColumnNames.HASh_VALUE)
private String hashValue;

@EmbeddedId
private Composite composite;

@PrePersist
private void onCreate() {
    referenceNumber = UUID.randomUUID();
    createdTime = ZonedDateTime.now();

}

public String getHashValue() {
    return hashValue;
}

public void setHashValue(String hashValue) {
    this.hashValue = hashValue;
}

public void setReferenceNumber(UUID referenceNumber) {
    this.referenceNumber = referenceNumber;
}
public Composite getComposite() {
    return composite;
}
public void setComposite(Composite composite) {
    this.composite = composite;
}

public Abc(Composite composite,String hashValue) {
    super();
    this.composite = composite;
    this.hashValue = hashValue;

}

public AadhaarVaultEntry() {
}


public ZonedDateTime getCreatedTime() {
    return createdTime;
}

public void setCreatedTime(ZonedDateTime createdTime) {
    this.createdTime = createdTime;
}

@Override
public boolean equals(Object theOther) {
    if (this == theOther)
        return true;
    if (!(theOther instanceof AadhaarVaultEntry))
        return false;
    AadhaarVaultEntry other = AadhaarVaultEntry.class.cast(theOther);
    return referenceNumber == null ? other.referenceNumber == null : referenceNumber.equals(other.referenceNumber);
}



@Override   public int hashCode() {
    return referenceNumber == null ? 0 : referenceNumber.hashCode();
}

}

我的Composite类是

   import java.io.Serializable;

   import javax.persistence.Embeddable;
    import javax.persistence.JoinColumn;
     import javax.persistence.ManyToOne;

  @Embeddable
  public class Composite implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = 1L;
private String encryptedNumber;


@ManyToOne
@JoinColumn(name = "Tenant_Id")
private Tenant tenantId;



public Tenant getTenantId() {
    return tenantId;
}


public void setTenantId(Tenant tenantId) {
    this.tenantId = tenantId;
}

public String getEncryptedNumber() {
    return encryptedNumber;
}


public void setEncryptedNumber(String theValue) {
    encryptedNumber = theValue;
}

public Composite()
{

}


public Composite(String encryptedNumber, Tenant tenantId) {
    super();
    this.encryptedNumber = encryptedNumber;
    this.tenantId = tenantId;
}


public Composite(String encryptedNumber) {
    super();
    this.encryptedNumber = encryptedNumber;
}


 }

在我的springbatch处理器中,我设置了cryptonumNumber,然后出现错误。

我的处理器类是

 @Component
 @Scope(value = "prototype")
 public class Processor implements ItemProcessor<BatchParameters,
  BatchParameters> {          

@Autowired
private IEncryptDecryptService encryptDecryptService;

@Override
public BatchParameters process(BatchParameters batchParameters) throws Exception {



    //encryption

    String encryptedNumber = encryptDecryptService.encrypt(batchParameters.getValue());


    batchParameters.getAbc().setComposite(new Composite(encryptedNumber));


    return batchParameters;
}
}

在设置encryptedNumber时,我得到了异常。它没有更新。为什么我得到了异常?实体表和处理器类中是否存在任何prpblem?

0 个答案:

没有答案