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

Got Keys were not fetched from database, Postgresql #65

Open
jankod opened this issue Aug 18, 2022 · 0 comments
Open

Got Keys were not fetched from database, Postgresql #65

jankod opened this issue Aug 18, 2022 · 0 comments

Comments

@jankod
Copy link

jankod commented Aug 18, 2022

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

@jankod jankod changed the title Got Keys were not fetched from database Got Keys were not fetched from database, Postgresql Aug 18, 2022
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

1 participant