2017-10-10 61 views
0

我想创建一个对象并保存ionto数据库插入jsonb到PostgreSQL的

Log l = new Log(); 

l.setTimestamp("creation_date", Util.getCurrentTimestamp()); 
l.setString("app_name", "name"); 
l.setString("log_type", "type"); 
l.setLong("user_id", 9l); 
l.setLong("module_element_id", 9); 
l.set("info", JsonHelper.toJsonString("{}")); 
l.save(); 

我试过多发silution但总是收到此错误:

ERROR: column "info" is of type jsonb but expression is of type character varying 

如何插入jsonb ?

编辑(DDL):

- 表:public.log

- DROP TABLE public.log;

CREATE TABLE public.log 
(
    id bigint NOT NULL DEFAULT nextval('log_id_seq'::regclass), 
    creation_date timestamp without time zone, 
    app_name text, 
    log_type text, 
    user_id bigint, 
    module_element_type bigint, 
    info jsonb, 
    CONSTRAINT log_pkey PRIMARY KEY (id) 
) 
WITH (
    OIDS=FALSE 
); 
ALTER TABLE public.log 
    OWNER TO postgres; 
+0

罗尼,你能否为你的桌子提供一个DDL? – ipolevoy

+0

当然,我编辑了我的帖子 – Rony

+0

Rony,我认为这个功能需要添加到PostgreSQL方言中,并且与https://github.com/javalite/activejdbc/issues/640相关。我试图找到Postgres文档,其中列出了所有具有这种奇怪语法的类型,但无法找到它。如果你发现,我会用它来将这个特性添加到框架中。 – ipolevoy

回答

0

该实现在当前框架中丢失。已经在https://github.com/javalite/activejdbc/issues/640中报告过。如果你能帮助追查Postgres的文档都在那里此语法使用PreparedStatement的Postgres的数据类型:

UPDATE my_table SET status = ?::status_type WHERE id = ? 

然后我会在一个位置,迅速实现它的PostgreSQL的方言:https://github.com/javalite/activejdbc/blob/master/activejdbc/src/main/java/org/javalite/activejdbc/dialects/PostgreSQLDialect.java