norm icon indicating copy to clipboard operation
norm copied to clipboard

DEFAULT values

Open ZZerog opened this issue 5 years ago • 1 comments

How catch created timestamp NOT NULL DEFAULT NOW() column with single pojo object?

I tried

    @GeneratedValue
    public Timestamp created;

with result: com.dieselpoint.norm.DbException: org.postgresql.util.PSQLException: Bad value for type long : 2020-03-30 22:46:54.724897

Thx

ZZerog avatar Mar 30 '20 20:03 ZZerog

Yes, by coincidence I ran into the same problem yesterday. My code assumed that generated values would only be int or long, which is obviously wrong. I need to redesign it.

There is a workaround: execute the insert or update as a query:

String sql = "insert into foo (bar) values ('bah') returning created";

Timestamp created = db.sql(sql).first(Timestamp.class);

The Postgres "returning" keyword returns a result set. You can do "returning *" to get all columns.

ccleve avatar Mar 31 '20 01:03 ccleve