Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEFAULT values #47

Open
ZZerog opened this issue Mar 30, 2020 · 1 comment
Open

DEFAULT values #47

ZZerog opened this issue Mar 30, 2020 · 1 comment

Comments

@ZZerog
Copy link

ZZerog commented Mar 30, 2020

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

@ccleve
Copy link
Member

ccleve commented Mar 31, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants