Reputation: 315
I'm using EclipseLink for JPA Persistence and I'm very new to this technology. I was in a situation I had to update an entry in the table in oracle database and I did commit for this update successfully in the database but It is not reflected in JPA Entity means I can't see the data in Front end but once i restart the tomcat server, I can see the data in the front end. Someone please help me what is happening from back end.
Thanks in advance!
SDS.java
import java.util.Date;
@Entity
@Table(name="SDS")
@XmlRootElement
public class SDS {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long sdsId;
@Column
private String sdsNumber;
@Column
private String sdsName;
@Column
private String sapId;
@Column(name = "DATE_FIELD")
@Temporal(TemporalType.TIMESTAMP)
private Date sdsDate;
public SDS() {}
public Long getSdsId() {
return sdsId;
}
public void setSdsId(Long sdsId) {
this.sdsId = sdsId;
}
public String getSdsNumber() {
return sdsNumber;
}
public void setSdsNumber(String sdsNumber) {
this.sdsNumber = sdsNumber;
}
public String getSdsName() {
return sdsName;
}
public void setSdsName(String sdsName) {
this.sdsName = sdsName.substring(0, Math.min(sdsName.length(), 254));
//this.sdsName = sdsName;
}
public Date getSdsDate() {
return sdsDate;
}
public void setSdsDate(Date sdsDate) {
this.sdsDate = sdsDate;
}
}
DB Update:
update SDS set date_field='10-FEB-2017' where sdsid=1102
Upvotes: 1
Views: 4673
Reputation: 51
Update may be not reflected because when you get your Entity with EntityManager's "find" method EntityManager finds it in the persistence context, not in the database.
If the entity instance is contained in the persistence context, it is returned from there
entityManager.refresh(entity) synchronized the entity with the database for me.
entityManager.flush() did not work (even with committing everything).
entityManager.clear() or obtaining a new EntityManager from EntityManagerFactory also did not help.
And it seems that the same happens when you use "createNativeQuery" with SQL SELECT instead of the "find" method.
Oh! Look what I found.
By default EclipseLink uses a shared object cache, that caches a subset of all objects read and persisted for the persistence unit. The EclipseLink shared cache differs from the local EntityManager cache. The shared cache exists for the duration of the persistence unit (EntityManagerFactory, or server) and is shared by all EntityManagers and users of the persistence unit. The local EntityManager cache is not shared, and only exists for the duration of the EntityManager or transaction.
The shared cache can also be disabled.
property name="eclipselink.cache.shared.default" value="false"
Upvotes: 5