0

我使用 postgres sql 作为数据库,使用 java 作为后端。我正在使用带有 java 代码的 sql2o,如下所示。

public Category insertCategory(Category category) {
        // TODO Auto-generated method stub
        System.out.println(category.getName());
        String query = getQuery("insertCategory");
        try (Connection conn = getConnection()) {
        conn.createQuery(query).bind(category).executeAndFetchFirst(Category.class);

            return null;
        }
        catch(Throwable t) {
            throw new RepositoryException(t);
        }
    }

类别类是包含名称、描述、标题等属性的模型。

public class Category extends Entity {
    private long id;
    private String name;
    private String description;
    private String title;
}

询问 :

insert into category(name, description, title, icon) values(:name, :description, :title, :icon) returning * 

我正在使用返回 * 来取回插入的记录,如上所示。但我收到以下错误

com.hiya.repo.utils.RepositoryException: org.sql2o.Sql2oException: Database error: No results were returned by the query.
    at com.hiya.repo.orientdb.CategoryServiceImpl.insertCategory(CategoryServiceImpl.java:70)
    at com.hiya.repo.orientdb.TestCategoryServiceImpl.testInsertCategory(TestCategoryServiceImpl.java:66)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 

我在某个地方出错了吗?

4

0 回答 0