分离的实体通过liquibase传递给持久性错误

时间:2016-08-08 14:01:50

标签: java spring hibernate

我有2个域名

@Entity
public class Model extends BaseLongIdModel {

    @NotNull
    @Size(min = 2, max = 50)
    @Column(length = 50, nullable = false)
    private String name;

    @NotNull
    @Column(nullable = false)
    private Long threshold;

    @OneToMany(mappedBy = "model", cascade = CascadeType.ALL, orphanRemoval = true)
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    private Set<ModelWeight> weights;

    public String getName() {
        return name;
    }

    public Model setName(String name) {
        this.name = name;
        return this;
    }

    public Long getThreshold() {
        return threshold;
    }

    public Model setThreshold(Long threshold) {
        this.threshold = threshold;
        return this;
    }

    public Set<ModelWeight> getWeights() {
        return weights;
    }

    public Model setWeights(Set<ModelWeight> weights) {
        this.weights = weights;
        return this;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this)
            .append("name", name)
            .append("threshold", threshold)
            .append("weights", weights)
            .toString();
    }
}




@Entity
public class Company extends BaseLongIdModel {
    @NotNull
    @Column(length = 64, nullable = false)
    private String name;
    @NotNull
    @Column(length = 32, nullable = false)
    private String merchantId;

    @Size(max = 255)
    @NotNull
    @Column(length = 255, nullable = false)
    private String companyAddress;
    @Size(max = 64)
    @NotNull
    @Column(length = 32, nullable = false)
    private String companyDistrict;
    @Size(max = 64)
    @NotNull
    @Column(length = 32, nullable = false)
    private String companyCity;
    @Size(max = 64)
    @NotNull
    @Column(length = 32, nullable = false)
    private String companyPhone;
    @Size(max = 64)
    @NotNull
    @Column(length = 32, nullable = false)
    private String companyContact;
    @Size(max = 64)
    @NotNull
    @Column(length = 32, nullable = false)
    private String companyContactMobilePhone;
    @Size(max = 64)
    @NotNull
    @Column(length = 32, nullable = false)
    private String companyCountry;

    @Size(max = 64)
    @NotNull
    @Column(length = 32, nullable = false)
    private String taxPayerType;

    @Size(max = 64)
    @NotNull
    @Column(length = 32, nullable = false)
    private String taxorIDNumber;

    @OneToMany(mappedBy = "company", cascade = CascadeType.ALL, orphanRemoval = true)
    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    private Set<Merchant> merchants;


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMerchantId() {
        return merchantId;
    }

    public void setMerchantId(String merchantId) {
        this.merchantId = merchantId;
    }



    public String getCompanyAddress() {
        return companyAddress;
    }

    public void setCompanyAddress(String companyAddress) {
        this.companyAddress = companyAddress;
    }

    public String getCompanyDistrict() {
        return companyDistrict;
    }

    public void setCompanyDistrict(String companyDistrict) {
        this.companyDistrict = companyDistrict;
    }

    public String getCompanyCity() {
        return companyCity;
    }

    public void setCompanyCity(String companyCity) {
        this.companyCity = companyCity;
    }

    public String getCompanyPhone() {
        return companyPhone;
    }

    public void setCompanyPhone(String companyPhone) {
        this.companyPhone = companyPhone;
    }

    public String getCompanyContact() {
        return companyContact;
    }

    public void setCompanyContact(String companyContact) {
        this.companyContact = companyContact;
    }

    public String getCompanyContactMobilePhone() {
        return companyContactMobilePhone;
    }

    public void setCompanyContactMobilePhone(String companyContactMobilePhone) {
        this.companyContactMobilePhone = companyContactMobilePhone;
    }

    public String getCompanyCountry() {
        return companyCountry;
    }

    public void setCompanyCountry(String companyCountry) {
        this.companyCountry = companyCountry;
    }

    public String getTaxPayerType() {
        return taxPayerType;
    }

    public void setTaxPayerType(String taxPayerType) {
        this.taxPayerType = taxPayerType;
    }

    public String getTaxorIDNumber() {
        return taxorIDNumber;
    }

    public void setTaxorIDNumber(String taxorIDNumber) {
        this.taxorIDNumber = taxorIDNumber;
    }

    public Set<Merchant> getMerchants() {
        return merchants;
    }

    public Company setMerchants(Set<Merchant> merchants) {
        this.merchants = merchants;
        return this;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (o == null || getClass() != o.getClass()) return false;

        Company company = (Company) o;

        return new EqualsBuilder()
            .append(name, company.name)
            .append(merchantId, company.merchantId)

            .append(companyAddress, company.companyAddress)
            .append(companyDistrict, company.companyDistrict)
            .append(companyCity, company.companyCity)
            .append(companyPhone, company.companyPhone)
            .append(companyContact, company.companyContact)
            .append(companyContactMobilePhone, company.companyContactMobilePhone)
            .append(companyCountry, company.companyCountry)
            .append(taxPayerType, company.taxPayerType)
            .append(taxorIDNumber, company.taxorIDNumber)
            .isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37)
            .append(name)
            .append(merchantId)

            .append(companyAddress)
            .append(companyDistrict)
            .append(companyCity)
            .append(companyPhone)
            .append(companyContact)
            .append(companyContactMobilePhone)
            .append(companyCountry)
            .append(taxPayerType)
            .append(taxorIDNumber)
            .toHashCode();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this)
            .append("name", name)
            .append("merchantId", merchantId)
            .append("companyAddress", companyAddress)
            .append("companyDistrict", companyDistrict)
            .append("companyCity", companyCity)
            .append("companyPhone", companyPhone)
            .append("companyContact", companyContact)
            .append("companyContactMobilePhone", companyContactMobilePhone)
            .append("companyCountry", companyCountry)
            .append("taxPayerType", taxPayerType)
            .append("taxorIDNumber", taxorIDNumber)
            .append("merchants", merchants)//// TODO: 06.08.2016 how
            .toString();
    }
}

错误就是

  

{&#34;时间戳&#34;:&#34; 2016-08-08T13:53:31.966 + 0000&#34;&#34;状态&#34; 500&#34;错误&#34 ;:&#34;内   服务器   错误&#34;&#34;例外&#34;:&#34; org.springframework.dao.InvalidDataAccessApiUsageException&#34;&#34;消息&#34;:&#34;分离   实体传递给persist:net.infoowl.fraud.domain.Merchant;嵌套   异常是org.hibernate.PersistentObjectException:分离的实体   传递坚持:   net.infoowl.fraud.domain.Merchant&#34;&#34;路径&#34;:&#34; / API /公司&#34;}

我试试

  <md-input-container flex-gt-xs>
        <label translate>company.merchants.title</label>
        <md-select ng-model="vm.model.merchants" md-on-close="vm.clearSearchTerm()" multiple=""
                   ng-model-options="{trackBy: '$value.id'}">
            <md-select-header>
                <input ng-model="vm.searchRuleTerm" type="text" placeholder="{{'company.merchants.search' | translate}}"
                       class="_md-text">
            </md-select-header>
            <md-optgroup>
                <md-option ng-value="merchant" ng-repeat="merchant in vm.merchants |filter: vm.searchRuleTerm">{{merchant.name}}
                </md-option>
            </md-optgroup>
        </md-select>
    </md-input-container>

0 个答案:

没有答案