How to convert MYSQL Query to JPQL Query? Instead of converting is it possible to use same query to update entity in Java swing Program?
mysql query select * from project.newproject; update newproject set pedate = date_add(psdate, interval duration day)
select * from project.newproject; update newproject set pedate = date_add(psdate, interval duration day)
My Entity class is showing below
@Entity
@Table(name = "newproject")
@XmlRootElement
@Transient
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "pid")
private Integer pid;
@Basic(optional = false)
@Column(name = "pname")
private String pname;
@Basic(optional = false)
@Column(name = "psdate")
@Temporal(TemporalType.DATE)
private Date psdate;
@Basic(optional = false)
@Column(name = "duration")
private int duration;
@Column(name = "pedate")
@Temporal(TemporalType.DATE)
private Date pedate;
I changed MYSQL Query as below to update selected row
`update newproject
set pedate = date_add(psdate, interval duration day)
where pid = newproject.pid;`
and used createnativeQuery in Java to update selected row
Newproject_1 p = ProjectPUEntityManager.find(Newproject_1.class, 1);
ProjectPUEntityManager.getTransaction().begin();
Query query = ProjectPUEntityManager.createNativeQuery("update newproject \n" +
"set pedate = date_add(psdate, interval duration day)\n" +
"where pid = newproject.pid;");
int count = query.executeUpdate();
ProjectPUEntityManager.merge(p);
ProjectPUEntityManager.getTransaction().commit();
JOptionPane.showMessageDialog(rootPane, "Update End Date");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.