From 607f63a7a1f9156202b1e6912ee1e6e589e05530 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 5 May 2011 19:02:38 +0000 Subject: [PATCH] Fixed a problem where the Postgres JDBC driver would call toString() on an enum, when we need it to be using name() instead. We just take care to send it the results of name() instead of the enum value itself. It would be nice to share this code with BuildVisitor.bindValue, but that would require yet further twisting and factoring of the code, obscuring it even more. We'll just hope that special cases like Enum and ByteEnum aren't going to keep cropping up. --- .../java/com/samskivert/depot/impl/PostgreSQL4Builder.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/samskivert/depot/impl/PostgreSQL4Builder.java b/src/main/java/com/samskivert/depot/impl/PostgreSQL4Builder.java index 08f6841..ca1d149 100644 --- a/src/main/java/com/samskivert/depot/impl/PostgreSQL4Builder.java +++ b/src/main/java/com/samskivert/depot/impl/PostgreSQL4Builder.java @@ -60,6 +60,11 @@ public class PostgreSQL4Builder extends PostgreSQLBuilder type = "smallint"; // tinyint is in the spec, but PG doesn't recognize? } else if (testValue instanceof Enum) { type = "varchar"; + // we need to replace the enum values with their name() because otherwise + // the Postgres JDBC driver will call toString() on them which is incorrect + for (int ii = 0; ii < values.length; ii++) { + values[ii] = ((Enum)values[ii]).name(); + } } else if (testValue instanceof Timestamp) { type = "timestamp"; } else if (testValue instanceof Date) {