small medium large xlarge

Generic-user-small
02 Apr 2016, 02:48
Shayne Koestler (1 post)

From the very beginning I have had trouble getting the h2 database to start. Running the first two commands in the book:

lein new luminus guestbook +h2 lein run

I noticed that this piece of output shown in the book was missing from my output.

[2016-02-29][INFO][guestbook.core] #’guestbook.db.core/db started

Then when calling the following function from the repl

(get-messages)

results in

IllegalArgumentException db-spec mount.core.DerefableState@bd9ab27 is missing a required parameter clojure.java.jdbc/get-connection (jdbc.clj:292

Any help would be much appreciated.

Pasfoto_pragsmall
02 Apr 2016, 08:01
Christiaan Janssen (2 posts)

I have the exacte same isseu:

IllegalArgumentException db-spec mount.core.DerefableState@6ff92798 is missing a required parameter  clojure.java.jdbc/get-connection (jdbc.clj:292)

And no idea what is going on.

I would like to add that I have the feeling the database in sot running, if I isseu a (stop) from the repl I get:

(stop)
[2016-04-02 09:59:39,317][DEBUG][org.projectodd.wunderboss.WunderBoss] Returning existing component for org.projectodd.wunderboss.web.Web:-1645144552, ignoring options.
[2016-04-02 09:59:39,331][INFO][luminus.http-server] HTTP server stopped
=> {:stopped ["#'guestbook.core/http-server"]}

And a (start) also only shows the http-server starting

Pasfoto_pragsmall
02 Apr 2016, 08:42
Christiaan Janssen (2 posts)

I found a solution! It seems that the database is not loaded when we do a start and stop command.

you need to do this:

;;switch to the namespace
(require '[guestbook.db.core :refer :all])

;; Start the database
(start)

;;check if we have any existing data
(get-messages)

That works for me

Profile_pic_pragsmall
02 Apr 2016, 21:46
Dmitri Sotnikov (136 posts)

What’s happening here is that mount won’t initialize the database state unless it’s referenced somewhere. When you require the namespace then it becomes referenced and then it will be started.

You can also start it explicitly by running (mount.core/start #'guestbook.config/env #'guestbook.db.core/*db*). Note that the *db* state depends on the env state to get the database connection, so both would need to be started.

However, once you start using the database in another namespace then everything will work as expected automatically.

Generic-user-small
15 Apr 2016, 17:26
Daniel Lobato Garcia (1 post)

I had the same issue - which (start) fixed.

Page 12 of the beta book doesn’t make any mention of this, so if the future versions could have this in the book I think it’d be more ‘error-proof’

Profile_pic_pragsmall
16 Apr 2016, 03:51
Dmitri Sotnikov (136 posts)

Good idea, I updated the wording to explain why the connection needs to be started manually.

Generic-user-small
21 Apr 2016, 00:03
yusef nathanson (1 post)

Just bought the book today. I’m suffering a different error with the database setup. When I run:

$ lein run migrate

I get this response:

[2016-04-20 19:38:12,958][DEBUG][org.jboss.logging] Logging Provider: org.jboss.logging.Log4jLoggerProvider
[2016-04-20 19:38:14,478][INFO][migratus.core] Starting migrations
[2016-04-20 19:38:14,843][INFO][migratus.database] creating migration table 'schema_migrations'
DEPRECATED: unrolled column specs / key/value arguments to create-table-ddl
[2016-04-20 19:38:14,850][INFO][migratus.core] Ending migrations
Exception in thread "main" java.lang.NullPointerException, compiling:(/private/var/folders/w5/0xydh_bj5sdgddlml7xwytyc0000gn/T/form-init228431613116001593.clj:1:124)
	at clojure.lang.Compiler.load(Compiler.java:7391)
	at clojure.lang.Compiler.loadFile(Compiler.java:7317)
	at clojure.main$load_script.invokeStatic(main.clj:275)
	at clojure.main$init_opt.invokeStatic(main.clj:277)
	at clojure.main$init_opt.invoke(main.clj:277)
	at clojure.main$initialize.invokeStatic(main.clj:308)
	at clojure.main$null_opt.invokeStatic(main.clj:342)
	at clojure.main$null_opt.invoke(main.clj:339)
	at clojure.main$main.invokeStatic(main.clj:421)
	at clojure.main$main.doInvoke(main.clj:384)
	at clojure.lang.RestFn.invoke(RestFn.java:421)
	at clojure.lang.Var.invoke(Var.java:383)
	at clojure.lang.AFn.applyToHelper(AFn.java:156)
	at clojure.lang.Var.applyTo(Var.java:700)
	at clojure.main.main(main.java:37)
Caused by: java.lang.NullPointerException
	at clojure.core$name.invokeStatic(core.clj:1546)
	at clojure.core$name.invoke(core.clj:1540)
	at clojure.java.jdbc$as_sql_name.invokeStatic(jdbc.clj:67)
	at clojure.java.jdbc$as_sql_name.invoke(jdbc.clj:56)
	at clojure.java.jdbc$create_table_ddl$spec_to_string__14400.invoke(jdbc.clj:1273)
	at clojure.core$map$fn__4785.invoke(core.clj:2646)
	at clojure.lang.LazySeq.sval(LazySeq.java:40)
	at clojure.lang.LazySeq.seq(LazySeq.java:49)
	at clojure.lang.Cons.next(Cons.java:39)
	at clojure.lang.LazySeq.next(LazySeq.java:81)
	at clojure.lang.RT.next(RT.java:688)
	at clojure.core$next__4341.invokeStatic(core.clj:64)
	at clojure.string$join.invokeStatic(string.clj:180)
	at clojure.string$join.invoke(string.clj:180)
	at clojure.java.jdbc$create_table_ddl.invokeStatic(jdbc.clj:1277)
	at clojure.java.jdbc$create_table_ddl.invoke(jdbc.clj:1254)
	at clojure.java.jdbc$legacy_create_table_ddl.invokeStatic(jdbc.clj:1293)
	at clojure.java.jdbc$legacy_create_table_ddl.doInvoke(jdbc.clj:1287)
	at clojure.lang.RestFn.invoke(RestFn.java:439)
	at clojure.java.jdbc$create_table_ddl.invokeStatic(jdbc.clj:1268)
	at clojure.java.jdbc$create_table_ddl.invoke(jdbc.clj:1254)
	at clojure.java.jdbc$create_table_ddl.invokeStatic(jdbc.clj:1264)
	at clojure.java.jdbc$create_table_ddl.invoke(jdbc.clj:1254)
	at migratus.database$init_schema_BANG_$fn__14842.invoke(database.clj:227)
	at clojure.java.jdbc$db_transaction_STAR_.invokeStatic(jdbc.clj:602)
	at clojure.java.jdbc$db_transaction_STAR_.invoke(jdbc.clj:574)
	at clojure.java.jdbc$db_transaction_STAR_.invokeStatic(jdbc.clj:587)
	at clojure.java.jdbc$db_transaction_STAR_.invoke(jdbc.clj:574)
	at migratus.database$init_schema_BANG_.invokeStatic(database.clj:220)
	at migratus.database$init_schema_BANG_.invoke(database.clj:219)
	at migratus.database.Database.connect(database.clj:262)
	at migratus.core$run.invokeStatic(core.clj:24)
	at migratus.core$run.invoke(core.clj:21)
	at migratus.core$migrate.invokeStatic(core.clj:63)
	at migratus.core$migrate.invoke(core.clj:60)
	at luminus_migrations.core$migrate.invokeStatic(core.clj:16)
	at luminus_migrations.core$migrate.invoke(core.clj:9)
	at guestbook.core$_main.invokeStatic(core.clj:57)
	at guestbook.core$_main.doInvoke(core.clj:52)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.lang.Var.invoke(Var.java:379)
	at user$eval15354.invokeStatic(form-init228431613116001593.clj:1)
	at user$eval15354.invoke(form-init228431613116001593.clj:1)
	at clojure.lang.Compiler.eval(Compiler.java:6927)
	at clojure.lang.Compiler.eval(Compiler.java:6917)
	at clojure.lang.Compiler.load(Compiler.java:7379)
	... 14 more

I’ve been messing with it for hours but I just get the same error.

It seems that JDBC has broken compatibility with migratus. Check their github here.

I’m quite new to programming and this is a little over my head.

Help will be greatly appreciated!

Profile_pic_pragsmall
21 Apr 2016, 04:00
Dmitri Sotnikov (136 posts)

You’re absolutely right. The latest clojure.java.jdbc API is incompatible. The fix is to rollback the conman library to version 0.4.9. I’ve updated the template accordingly as well. Sorry for the inconvenience.

Generic-user-small
27 Apr 2016, 12:19
Aditya Gore (1 post)

I had the same trouble starting the database as reported by others: “IllegalArgumentException db-spec mount.core.DerefableState@58922dd5 is missing…” etc. and (start) fixed it. Just leaving this comment here for completeness.

Generic-user-small
20 May 2016, 16:55
Patrick Huffer (8 posts)

I tried the following as described above but got an error:

(require '[guestbook.db.core :refer :all])
(start)
(get-messages)
;; java.lang.RuntimeException: Unable to resolve symbol: get-messages in this context

Instead I have to add the namespace in order to get the generated functions to work.

(guestbook.db.core/get-messages)
;; => ()

Not sure what is going wrong?

Profile_pic_pragsmall
21 May 2016, 04:14
Dmitri Sotnikov (136 posts)

Hmm, you should be able to call the functions from the namespace once you require it. The steps should be as follows.

run the app in a terminal with:

lein run

run the REPL in a separate terminal from the app directory

lein repl :connect 7000

In the REPL, you should be able to require the namespace, run (start), and call the functions:

(require '[guestbook.db.core :refer :all])
(start)
(get-messages)
Generic-user-small
31 May 2016, 04:07
Paul Gowder (4 posts)

Can I suggest adding a note along those lines to the non-relational databases appendix too? I just ended up here after rooting around trying to figure out how to get mongodb running from the template.

Actually, that’s something that could be in the startup “you need to connect your database” messages that show up on the default home page for the template too. Right now, it just says “start the database and give it a reference in the env,” not “and also reference the namespace somewhere before restarting or it won’t start.” (Would you entertain a PR along those lines?)

Profile_pic_pragsmall
31 May 2016, 12:25
Dmitri Sotnikov (136 posts)

I agree, a note regarding that would probably be helpful. If you’re up for making a PR for improved docs I’d be glad to integrate it.

Generic-user-small
31 May 2016, 16:31
Paul Gowder (4 posts)

Totally, will do. :-)

Profile_pragsmall
30 Apr 2017, 02:22
Geoffrey Clements (22 posts)

Fighting with this too. Bought the book today and started working through it. Created the guestbook project using the version of luminus specified in the book. Got the guestbook table missing error. (Migrations finished but didn’t actually run.) Fussed with it. Got frustrated. Deleted everything tried the latest version of luminus. Same issue. Finally looked up pragprog.com and found this thread. Tried reverting to corman 0.4.9 in the current version of luminus. Nope. Tried the version of luminus specified in the book with corman reverted back to 0.4.9. Migrations still don’t run and I get the exception:

Exception in thread "main" java.lang.ClassCastException: clojure.lang.PersistentVector (in module: Unnamed Module) cannot be cast to clojure.lang.Named (in module: Unnamed Module), compiling:(/tmp/form-init2580785282838157891.clj:1:73)

:(

Profile_pic_pragsmall
30 Apr 2017, 15:09
Dmitri Sotnikov (136 posts)

I just created a fresh project and I’m not able to reproduce the issue here:

lein new luminus guestbook +h2
cd guestbook

add migration files under resources/migrations/:

  • 20150719215253-guestbook.i[.sql:
-- START:guestbook-table
CREATE TABLE guestbook
(id INTEGER PRIMARY KEY AUTO_INCREMENT,
 name VARCHAR(30),
 message VARCHAR(200),
 timestamp TIMESTAMP);
-- END:guestbook-table
  • 20150719215253-guestbook.down.sql
DROP TABLE guestbook;

Next, I run:

lein run migrate
2017-04-30 11:02:57,380 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
read config from resource: "config.edn"
read config from file: ".lein-env"
2017-04-30 11:02:59,235 [main] INFO  migratus.core - Starting migrations
2017-04-30 11:02:59,506 [main] INFO  migratus.database - creating migration table 'schema_migrations'
2017-04-30 11:02:59,552 [main] INFO  migratus.core - Running up for [20150719215253]
2017-04-30 11:02:59,553 [main] INFO  migratus.core - Up 20150719215253-guestbook
2017-04-30 11:02:59,570 [main] DEBUG migratus.database - found 1 up migrations
2017-04-30 11:02:59,590 [main] DEBUG migratus.database - marking 20150719215253 complete
2017-04-30 11:02:59,594 [main] INFO  migratus.core - Ending migrations

Note that the log indicates the migration it ran. Now I can run the REPL and confirm that the table exists and I can query it:

lein repl
2017-04-30 11:08:35,642 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
nREPL server started on port 50863 on host 127.0.0.1 - nrepl://127.0.0.1:50863
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.8.0
OpenJDK 64-Bit Server VM 1.8.0_112-b16
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=> (use 'guestbook.db.core)
nil
user=> (start)
read config from resource: "config.edn"
read config from file: ".lein-env"
2017-04-30 11:08:48,749 [nREPL-worker-0] INFO  guestbook.env -
-=[guestbook started successfully using the development profile]=-
2017-04-30 11:08:48,852 [nREPL-worker-0] INFO  luminus.http-server - starting HTTP server on port 3000
2017-04-30 11:08:48,888 [nREPL-worker-0] INFO  org.xnio - XNIO version 3.3.6.Final
2017-04-30 11:08:49,009 [nREPL-worker-0] INFO  org.projectodd.wunderboss.web.Web - Registered web context /
{:started ["#'guestbook.config/env"
           "#'guestbook.handler/init-app"
           "#'guestbook.core/http-server"
           "#'guestbook.db.core/*db*"]}
user=> (get-messages {})
()
user=> (save-message! {:name "Bob" :message "Hello" :timestamp (java.util.Date.)})
1
user=> (get-messages {})
({:id 1
  :message "Hello"
  :name "Bob"
  :timestamp #inst "2017-04-30T15:09:11.555-00:00"})
Generic-user-small
03 May 2017, 22:46
Roy Freeman (2 posts)

Hi, just bought the book and all was going well till I tried to start the database. on doing this in repl connected to port 7000

(require ‘[guestbook.db.core :refer :all])

i get this error

CompilerException clojure.lang.ExceptionInfo: Missing HugSQL Header of :name, :name-, :snip, or :snip- Found headers include: [:get-messages :doc] SQL: [“SELECT * from guestbook”] {}, compiling:(guestbook/db/core.clj:16:1)

any clues

Profile_pic_pragsmall
03 May 2017, 22:53
Dmitri Sotnikov (136 posts)

Unfortunately, I haven’t seen this error before and I’m not able to reproduce it locally. A couple of things to check would be the version of the JDK and Leiningen that you have.

Generic-user-small
04 May 2017, 09:36
Roy Freeman (2 posts)

lein - version reports

Leiningen 2.7.1 on Java 1.8.0_102 Java HotSpot(TM) 64-Bit Server VM

I deleted the project and started again. The only change I made was to follow the online tutorial which edits the migrations files rather than as stated in the book to delete them and create new ones using migratus?

Profile_pic_pragsmall
04 May 2017, 21:43
Dmitri Sotnikov (136 posts)

That all looks fine, and there shouldn’t be any problem deleting the migration files and making new ones. If you can post the project on GitHub, I could take a look and see if I can replicate the issue locally.

Profile_pragsmall
10 May 2017, 03:06
Geoffrey Clements (22 posts)

Hi,

I finally had a chance to retry starting guestbook again on a different machine running MacOS instead of Ubuntu and this time the migrations ran fine and queries work. My guess is something is broken in the setup of my Ubuntu machine. Feel free to delete/ignore my comment above since this is working for me now. :)

geoff

Profile_pic_pragsmall
10 May 2017, 03:35
Dmitri Sotnikov (136 posts)

Glad to hear it’s working. I wonder what was causing the problem on the Linux machine. The JVM is typically fairly platform independent. If you do get a chance to figure it out let me know.

Generic-user-small
01 Sep 2017, 04:28
Curtis Wallen (2 posts)

I’m having a similar problem to those above and it seems some people on GitHub have had the same problem.

[2016-02-29][INFO][guestbook.core] #'guestbook.db.core/*db* started is absent when I first execute lein run

And when I execute lein run migrate it appears to create the db but not the table:

guestbook curtis$ lein run migrate
[2017-08-31 21:18:48,062][DEBUG][org.jboss.logging] Logging Provider: org.jboss.logging.Log4jLoggerProvider
[2017-08-31 21:18:48,942][INFO][migratus.core] Starting migrations
[2017-08-31 21:18:49,186][INFO][migratus.database] creating migration table 'schema_migrations'
[2017-08-31 21:18:49,350][INFO][migratus.core] Ending migrations

I’ve tried everything suggested in this thread and on Github, but with no success. Any thoughts? I’m running macOS 10.12.6 and have set the plugin reference in .lein/profiles.clj to luminus/lein-template "2.9.10.74"

EDIT: I uninstalled/reinstalled Leiningen and it seems to be working now. I also ran lein run migrate before lein run on the attempt when it worked. Not sure if that matters.

Profile_pic_pragsmall
01 Sep 2017, 13:39
Dmitri Sotnikov (136 posts)

You definitely need to run lein run migrate first to create the database. The only other thing to be aware of is that the guestbook.db.core namespace need to be referred somewhere for it to be started automatically.

The mount library that manages the state of the database follows the namespace hierarchy to infer what resources need to be started. It starts from the guestbook.core namespace, and follows the hierarchy from there.

Generic-user-small
03 Sep 2017, 19:49
Curtis Wallen (2 posts)

Weird I think cider was somehow conflicting with the migration process?

Started running into the problem again:

norun curtis$ lein run migrate
[2017-09-03 15:42:53,476][DEBUG][org.jboss.logging] Logging Provider: org.jboss.logging.Log4jLoggerProvider
[2017-09-03 15:42:54,392][INFO][migratus.core] Starting migrations
[2017-09-03 15:42:54,642][INFO][migratus.database] creating migration table 'schema_migrations'
[2017-09-03 15:42:54,799][INFO][migratus.core] Ending migrations

Notice it never actually ran the up to create the table.

When I tried to run that migration my ~/.lein/profiles.clj included [cider/cider-nrepl "0.8.1"]

I took the cider plugin out and tried to run the migration again and it worked properly:

norun curtis$ lein run migrate
[2017-09-03 15:46:33,366][DEBUG][org.jboss.logging] Logging Provider: org.jboss.logging.Log4jLoggerProvider
[2017-09-03 15:46:34,304][INFO][migratus.core] Starting migrations
[2017-09-03 15:46:34,577][INFO][migratus.core] Running up for [20170903154358]
[2017-09-03 15:46:34,577][INFO][migratus.core] Up 20170903154358-newdb
[2017-09-03 15:46:34,582][DEBUG][migratus.database] found 1 up migrations
[2017-09-03 15:46:34,602][DEBUG][migratus.database] marking 20170903154358 complete
[2017-09-03 15:46:34,610][INFO][migratus.core] Ending migrations

A bit annoying, but good to know for anyone else potentially running into this problem.

You must be logged in to comment