anima icon indicating copy to clipboard operation
anima copied to clipboard

Got Keys were not fetched from database, Postgresql

Open jankod opened this issue 1 year ago • 0 comments

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 avatar Aug 18 '22 18:08 jankod