I'm creating a task module and the requirement is as follow:
When user completed the task, copy the current task and change the completion date property to null and add to the database. Is there any example that copy the persistent object then add to the database?
@Override public String update() { if (this.instance.getTaskCompleted().equals("Y")) { try { TitleXiTaskHome titleXiTask = (TitleXiTaskHome) super.clone(); titleXiTask.instance.setTaskCompleted("N"); titleXiTask.instance.setCompletedDate(null); titleXiTask.persist(); } catch (CloneNotSupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } super.update(); return "success"; }
Clone won't work (read the javadoc for it for a start), and I don't think you want to clone the *Home* object... You just need to write a method to copy the object I think.