I'm using jOOQ 3.8.4 and PostgreSQL 9.5 in a Spring 4 application. I have the following table and type definition
CREATE DOMAIN shop.money_amount AS numeric(6,2) DEFAULT 0 NOT NULL CHECK (value > 0::numeric);
CREATE TYPE shop.money AS (
m_amount shop.money_amount,
m_currency shop.currency,
m_country shop.site_country
);
CREATE TYPE shop.money_mapping AS (
mm_moneys shop.money []
);
CREATE TABLE shop.article
(
a_id bigserial NOT NULL,
a_price shop.money_mapping NOT NULL,
CONSTRAINT a_pk_id PRIMARY KEY (a_id)
);
Then I tried an insert using jOOQ, i.e.:
MoneyMappingRecord priceMoneyMapping = new MoneyMappingRecord();
priceMoneyMapping.setMoneys(new MoneyRecord[]{
new MoneyRecord().setAmount(new BigDecimal("11")).setCountry(SiteCountry.US).setCurrency(Currency.USD),
new MoneyRecord().setAmount(new BigDecimal("14")).setCountry(SiteCountry.DE).setCurrency(Currency.EUR)
});
dsl.insertInto(ARTICLE)
.set(ARTICLE.A_PRICE, priceMoneyMapping)
.returning(ARTICLE.A_ID).fetchOne().getId();
Then I get:
Caused by: org.springframework.jdbc.BadSqlGrammarException: jOOQ;
bad SQL grammar [insert into "shop"."article" ("a_price") values
(row(?::money[])) returning "shop"."article"."a_id"]; nested
exception is org.postgresql.util.PSQLException:
ERROR: cannot cast type record to shop.money_mapping
Detail: Cannot cast type money[] to shop.money[] in column 1.
What am I doing wrong?
UPDATE
I tried to rename the shop.money type as suggested by Lukas (from shop.money
to shop.localized_money
), but I believe that the problem is related to the schema. See the updated error.
Caused by: org.springframework.jdbc.BadSqlGrammarException:
jOOQ; bad SQL grammar [insert into "shop"."article" ("a_price")
values (row(?::localized_money[])) returning "shop"."article"."a_id"]; nested exception is
org.postgresql.util.PSQLException: ERROR: type "localized_money[]" does not exist
Maybe the type in type is an issue!