1

I want to create an object and save it ionto the DB

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();

I've tried mutiple silution but always get this error:

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

How to insert a jsonb?

edit (DDL):

-- Table: 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;
5
  • Rony, can you please provide a DDL for your table? Commented Oct 10, 2017 at 14:59
  • Sure, I edited my post Commented Oct 10, 2017 at 15:55
  • Rony, I think this functionality needs to be added to the PostgreSQL dialect and related to: github.com/javalite/activejdbc/issues/640. I was trying to find Postgres documentation where it lists all the types that have this strange syntax, but was unable tofind it. If you find, it I will use to add this feature to the framework. Commented Oct 10, 2017 at 18:01
  • ok, thanks for you answer. If I find it I'll let you know. Commented Oct 11, 2017 at 15:07
  • the implementation was added, please see the answer below Commented Jan 4, 2022 at 22:38

1 Answer 1

1

This implementation is missing in the framework currently. It was already reported in https://github.com/javalite/activejdbc/issues/640. If you can help tracking down Postgres documentation for all the Postgres data types where this syntax is used with PreparedStatement:

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

I will then be in a position to quickly implement it for the PostgreSQL dialect: https://github.com/javalite/activejdbc/blob/master/activejdbc/src/main/java/org/javalite/activejdbc/dialects/PostgreSQLDialect.java

Update Jan 4 2022:

The implementation was added to the SNAPSHOT-3.0 and will make it to a next release 3.0 for Java 16.

You can see the discussion here: https://github.com/javalite/javalite/issues/640

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.