Skip to content

Got Keys were not fetched from database, Postgresql #65

Description

@jankod

Exception in thread "main" org.sql2o.Sql2oException: Keys were not fetched from database. Please set the returnGeneratedKeys parameter in the createQuery() method to enable fetching of generated keys.
at org.sql2o.Connection.getKey(Connection.java:190)
at com.hellokaton.anima.core.AnimaQuery.save(AnimaQuery.java:1241)
at com.hellokaton.anima.Model.save(Model.java:28)

My Postgresql database DDL:

CREATE TABLE users (
	id serial PRIMARY KEY,
	user_name varchar(100) NOT NULL,
	age int8 NULL,
);

My Java code:

Anima db = Anima.open("jdbc:postgresql://127.0.0.1/db", "user", "pass");

User u = new User();
u.setAge(22);
u.setUserName("pero");
u.save();


@Data
@Table(name = "users", pk = "id")
public class User extends Model {

    private Integer id;
    private String  userName;
    private Integer age;

}

I found soulution:

 Anima db = Anima.open("jdbc:postgresql://127.0.0.1/db", "user", "pass, new PostgresQuirks() {
        @Override
        public boolean returnGeneratedKeysByDefault() {
            return true;
        }
    });

but then u.getId() return null

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions