Question

I have a DB table that uses the following schema:

CREATE TABLE users
(id SERIAL PRIMARY KEY,
  username TEXT UNIQUE NOT NULL,
  password TEXT NOT NULL,
  email TEXT NOT NULL,
  admin BOOLEAN NOT NULL,
  active BOOLEAN NOT NULL,
  created DATE NOT NULL);

I use Korma by defining a users entity

(defentity users
           (has-many tips))

And I try to seed values using the following functions:

(defn make-user-vals [username pass email]
  "Creates an active, non-admin user"
  {:username username, 
   :password (crypt/encrypt pass), 
   :email email,
   :admin false,
   :active true,
   :created (java.util.Date.)})

(defn seed-users! []
  (insert ent/users
    (values 
      (users/make-user-vals "admin" "f00b4r" "foo@example.com"))))

(seed-users!) fails with the following (not really informative to my eyes) message:

Failure to execute query with SQL:
INSERT INTO users (username, password, email, admin, active, created) VALUES (?, ?, ?, FALSE, TRUE, ?)  ::  [admin $2a$10$AVdxz9HvYOyszhcXVrTVi.oBcbz9EZVfGZYNUI3iDMb0hj3igvpEy foo@example.com #<Date Wed Feb 15 21:59:10 CET 2012>]
ClassCastException java.lang.RuntimeException cannot be cast to java.sql.SQLException  clojure.java.jdbc/print-sql-exception (jdbc.clj:350)

Any idea why?

(if that helps, querying the DB works, so it does not look like a connection problem)

Thanks!

Was it helpful?

Solution

You need to use java.sql.Date rather than java.util.Date:

(java.sql.Date. 2012 2 16)

Incidentally, you might want to investigate clj-time as a time-handling solution. Java's standard time-and-date-related classes are completely insane (as evidenced by the present issue).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top