实体内的列表不刷新

时间:2017-05-02 19:14:44

标签: java jpa netbeans

我正在使用JPA并且我有一个具有关系的实体(一对多),该实体被称为“Part”,其中包含一个名为“ProcessEstimate”的进程列表,但是当我向数据库插入一个新的“ ProcessEstimate“,”Part“里面的列表它没有更新,因为它仍然显示我插入之前的”ProcessEstimate“列表。

如何在不避开缓存的情况下更新列表?

这是我的部分实体:

@Entity
public class Part implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String name;
private int quantity;                 

private String notes;
private boolean materialProvided;

@ManyToOne
private Project project;
@OneToOne(cascade=CascadeType.ALL)
private DataFile dataFile;

private String material;   

@OneToMany(mappedBy = "part", cascade = CascadeType.ALL)
private List<ProcessEstimate> processes;

public Part(){        
    processes = new LinkedList<>();
}

public Long getId() {
    return id;
}

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

@Override
public int hashCode() {
    int hash = 0;
    hash += (id != null ? id.hashCode() : 0);
    return hash;
}

@Override
public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof Part)) {
        return false;
    }
    Part other = (Part) object;
    return !((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id)));
}

@Override
public String toString() {
    return String.valueOf(id);
}


/**
 * @return the quantity
 */
public int getQuantity() {
    return quantity;
}

/**
 * @param quantity the quantity to set
 */
public void setQuantity(int quantity) {
    this.quantity = quantity;
}

/**
 * @return the notes
 */
public String getNotes() {
    return notes;
}

/**
 * @param notes the notes to set
 */
public void setNotes(String notes) {
    this.notes = notes;
}

/**
 * @return the materialProvided
 */
public boolean isMaterialProvided() {
    return materialProvided;
}

/**
 * @param materialProvided the materialProvided to set
 */
public void setMaterialProvided(boolean materialProvided) {
    this.materialProvided = materialProvided;
}

/**
 * @return the dataFile
 */
public DataFile getDataFile() {
    return dataFile;
}

/**
 * @param dataFile the dataFile to set
 */
public void setDataFile(DataFile dataFile) {
    this.dataFile = dataFile;
}


/**
 * @return the name
 */
public String getName() {
    return name;
}

/**
 * @param name the name to set
 */
public void setName(String name) {
    this.name = name;
}       

/**
 * @return the project
 */
public Project getProject() {
    return project;
}

/**
 * @param project the project to set
 */
public void setProject(Project project) {
    this.project = project;
}            

/**
 * @return the processes
 */
public List<ProcessEstimate> getProcesses() {
    return processes;
}

/**
 * @param processes the processes to set
 */
public void setProcesses(List<ProcessEstimate> processes) {
    this.processes = processes;
}

/**
 * @return the material
 */
public String getMaterial() {
    return material;
}

/**
 * @param material the material to set
 */
public void setMaterial(String material) {
    this.material = material;
}

}

这是我的ProcessEstimate实体:

@Entity
public class ProcessEstimate implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
private Part part;

@OneToOne
private Process process;

private String typeTime;

@Column(name = "PROCESS_TIME")
private float time;

public Long getId() {
    return id;
}

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

@Override
public int hashCode() {
    int hash = 0;
    hash += (id != null ? id.hashCode() : 0);
    return hash;
}

@Override
public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof ProcessEstimate)) {
        return false;
    }
    ProcessEstimate other = (ProcessEstimate) object;
    return !((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id)));
}

@Override
public String toString() {
    return String.valueOf(id);
}

/**
 * @return the part
 */
public Part getPart() {
    return part;
}

/**
 * @param part the part to set
 */
public void setPart(Part part) {
    this.part = part;
}

/**
 * @return the process
 */
public Process getProcess() {
    return process;
}

/**
 * @param process the process to set
 */
public void setProcess(Process process) {
    this.process = process;
}

/**
 * @return the time
 */
public float getTime() {
    return time;
}

/**
 * @param time the time to set
 */
public void setTime(float time) {
    this.time = time;
}

/**
 * @return the typeTime
 */
public String getTypeTime() {
    return typeTime;
}

/**
 * @param typeTime the typeTime to set
 */
public void setTypeTime(String typeTime) {
    this.typeTime = typeTime;
}

}

抱歉我的英语不好。

0 个答案:

没有答案