簡體   English   中英

無法將java.lang.String字段CustomersEntity.address設置為CustomersEntity,CustomerEntity中的address字段有問題嗎?

[英]Can not set java.lang.String field CustomersEntity.address to CustomersEntity,Is something wrong with the address field in CustomerEntity?

我試圖通過休眠將一個新的CustomersEntity實例保存到我的數據庫中。 調試后,導致我的錯誤的確切行是:“ session.save(newCustomer)”我已經打印了此“ newCustomer”的內容,並且所有字段都存在,但ID字段除外。 我很確定自己已經為冬眠正確地注釋了我的ID字段,但是我可能是錯的。 我一直堅持這一點,因此非常感謝任何見解。

import org.springframework.stereotype.Indexed;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;

@Entity
@Indexed
@Table(name = "customers", schema = "customer_db", catalog = "")
    public class CustomersEntity {
    private String lastName;
    private String firstName;
    private String email;
    private String address;
    private String city;
    private String state;
    private String zip;
    private Timestamp lastEmailSent;

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int customerId;



@Basic
@Column(name = "lastName")
public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

@Basic
@Column(name = "firstName")
public String getFirstName() {
    return firstName;
}

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

@Basic
@Column(name = "email")
public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

@Basic
@Column(name = "address")
public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

@Basic
@Column(name = "city")
public String getCity() {
    return city;
}

public void setCity(String city) {
    this.city = city;
}

@Basic
@Column(name = "state")
public String getState() {
    return state;
}

public void setState(String state) {
    this.state = state;
}

@Basic
@Column(name = "zip")
public String getZip() {
    return zip;
}

public void setZip(String zip) {
    this.zip = zip;
}

@Basic
@Column(name = "lastEmailSent")
public Timestamp getLastEmailSent() {
    return lastEmailSent;
}

public void setLastEmailSent(Timestamp lastEmailSent) {
    this.lastEmailSent = lastEmailSent;
}


@Column(name = "customerId")
public int getCustomerId() {
    return customerId;
}
public void setCustomerId(int customerId) {
    this.customerId = customerId;
}


@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    CustomersEntity that = (CustomersEntity) o;
    return customerId == that.customerId &&
            Objects.equals(lastName, that.lastName) &&
            Objects.equals(firstName, that.firstName) &&
            Objects.equals(email, that.email) &&
            Objects.equals(address, that.address) &&
            Objects.equals(city, that.city) &&
            Objects.equals(state, that.state) &&
            Objects.equals(zip, that.zip) &&
            Objects.equals(lastEmailSent, that.lastEmailSent);
}

@Override
public int hashCode() {

    return Objects.hash(lastName, firstName, email, address, city, state, 
    zip, lastEmailSent, customerId);
}

}

我收到錯誤消息“無法將java.lang.String字段... model.CustomersEntity.address設置為... model.CustomersEntity。關於問題的任何見解?如果我的問題觸發了任何人,我感到抱歉。

聽起來在您嘗試保存該實體的代碼中,您是使用實體本身而不是地址字符串來設置地址。

我建議您在創建客戶對象的地方檢查控制器邏輯。 另外,請確保休眠映射文件中的屬性聲明正確。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM