Hi Guys,
I have been trying to solve an issue with my entity. I get this exception everytime to try to update an object ; javax.persistence.EntityNotFoundException: Unable to find com.nibssplc.icadservice.entity.Institution with id 3. In the database, the specified ID actually exists.
The entityCode:
public class InstitutionBranch extends AbstractFlag implements Serializable, com.nibssplc.icadservice.admin.model.Entity {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "institutionbranchid")
private Long branchId;
@Basic(optional = false)
// @NotNull
@Size(min = 1, max = 64)
@Column(name = "branchname")
private String branchName;
@Basic(optional = false)
//@NotNull
@Column(name = "createddate")
@Temporal(TemporalType.TIMESTAMP)
private Date createdDate;
@Basic(optional = false)
//@NotNull
//@Size(min = 1, max = 5)
@Column(name = "flag", length = 5)
private String flag;
@Size(max = 150)
@Column(name = "location")
private String location;
@Basic(optional = false)
// @NotNull
@Size(min = 1, max = 10)
@Column(name = "branchcode")
private String branchCode;
@JoinColumn(name = "institution", referencedColumnName = "institutionid")
@ManyToOne(optional = false, fetch = FetchType.EAGER)
private Institution institution;
// @XmlTransient
// @OneToMany(cascade = CascadeType.ALL, mappedBy = "branch", fetch = FetchType.LAZY)
// private List<UserIdentity> userIdentityList;
public InstitutionBranch() {
}
public InstitutionBranch(Long branchId) {
this.branchId = branchId;
}
public Long getBranchId() {
return branchId;
}
public void setBranchId(Long branchId) {
this.branchId = branchId;
}
public String getBranchName() {
return branchName;
}
public void setBranchName(String branchName) {
this.branchName = branchName;
}
@XmlTransient
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
@Override
public String getFlag() {
return flag;
}
@Override
public void setFlag(String flag) {
this.flag = flag;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getBranchCode() {
return branchCode;
}
public void setBranchCode(String branchCode) {
this.branchCode = branchCode;
}
@XmlTransient
public Institution getInstitution() {
return institution;
}
public void setInstitution(Institution institution) {
this.institution = institution;
}
@Override
public int hashCode() {
int hash = 0;
hash += (branchId != null ? branchId.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 InstitutionBranch)) {
return false;
}
InstitutionBranch other = (InstitutionBranch) object;
if ((this.branchId == null && other.branchId != null) || (this.branchId != null && !this.branchId.equals(other.branchId))) {
return false;
}
return true;
}
@Override
public String toString() {
return getClass().getSimpleName() + "[ branchId=" + branchId + " ]";
}
@XmlTransient
@Override
public Object getEntityId() {
return branchId;
}
@Transient
private Long institutionId;
public Long getInstitutionId() {
return institutionId;
}
// @XmlElement
// public String getInstitutionName() {
// return getInstitution() != null ? getInstitution().getInstitutionName() : null;
// }
}
The implementing methodCode:
public T update(T item) {
T t = null;
try
{
t = (T) this.em.merge(item);
this.em.flush();
this.em.refresh(t);
}
catch(Exception e)
{
System.out.println("WARNING [ERROR] IN update() ");
e.printStackTrace();
}
return t; //(T) this.entityManager.merge(item);
}
Please help me resolve . Thanks