Recently have a requirement on using custom Enum type on Postgres database, but when I trying to insert test data with DbSetup, the following exception thrown:
Cause: org.postgresql.util.PSQLException: ERROR: column "animal_type" is of type currency but expression is of type character varying
The reason is that, to insert data with JDBC prepared statement, the query needs to be in form:
INSERT INTO pet (pet_id, pet_type, name) VALUES (?, ?::animal_type, ?);
Please refer this site for more details: http://www.gotoquiz.com/web-coding/programming/java-programming/convert-between-java-enums-and-postgresql-enums/
By digging into the source code, the only way I found to solve this problem is hacking the Insert#execute method (
)
I am wondering, is there any other convenient way to achieve this?
Thanks in advance!
Recently have a requirement on using custom Enum type on Postgres database, but when I trying to insert test data with DbSetup, the following exception thrown:
Cause: org.postgresql.util.PSQLException: ERROR: column "animal_type" is of type currency but expression is of type character varyingThe reason is that, to insert data with JDBC prepared statement, the query needs to be in form:
INSERT INTO pet (pet_id, pet_type, name) VALUES (?, ?::animal_type, ?);Please refer this site for more details: http://www.gotoquiz.com/web-coding/programming/java-programming/convert-between-java-enums-and-postgresql-enums/
By digging into the source code, the only way I found to solve this problem is hacking the Insert#execute method (
DbSetup/src/main/java/com/ninja_squad/dbsetup/operation/Insert.java
Line 257 in f9f9fd5
I am wondering, is there any other convenient way to achieve this?
Thanks in advance!