简体   繁体   中英

Hibernate Update not working…using Spring framework

POJO:

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;

@Basic(optional = false)
@Column(name = "name")
private String name;

@Generated(GenerationTime.INSERT)
@Basic(optional = false)
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;

@Generated(GenerationTime.ALWAYS)
@Basic(optional = false)
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;

Controller:

@Controller
@RequestMapping(value = "/")
public class HomeController {
    @Autowired
    private NameDao nDao;

    @RequestMapping(value="/update/{id}", method=RequestMethod.GET)
    public String getUpdate(@PathVariable int id, Model model){
        Stamp st = (Stamp) nDao.getById(id);
        model.addAttribute("s", st);
        return "update";
    }

    @RequestMapping(value="/update/{id}", method=RequestMethod.POST)
    public String postUpdate(@ModelAttribute Stamp s){
        nDao.updateName(s);
        return "redirect:/";
    }

Update.jsp:

<h1>Update Here...</h1>
    <form method = "post">
        <div>
            <label>Name: </label><input type="text" value="${s.name}" name="name">
        </div>
        <input type="submit" value="Submit">
    </form>

My only concern is using the createdAt and updatedAt for each entry. On using createdAt and updatedAt dateTime, the problem of updating arose. Update now working. Any solution to use dateTime for createdAt and updatedAt working with upadate operation. Insert option works fine here.

使用@CreationTimestamp和@UpdateTimestamp,而不是手动设置这些值

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM