How to map timestamp column to JPA type?

后端 未结 4 1661
半阙折子戏
半阙折子戏 2021-01-04 18:15

I\'m using Play! 1.2.4 and PostgreSQL 9.1. I created a table with a created_at column, of type: timestamp without time zone. It has a default val

4条回答
  •  伪装坚强ぢ
    2021-01-04 18:29

    You need to detach and fetch entity from db. Insert statement does not contain created_at field so it's not managed by JPA at the time of creation. In repository it would look like this:

    @Transactional
    public Log save(Log log) {
        this.em.persist(log);
        this.em.detach(log);
        return this.em.find(Log.class, log.getId());
    }
    

提交回复
热议问题