"Entity used in relationship does not exist" in lein run

120 views
Skip to first unread message

Simon Holgate

unread,
Jan 27, 2012, 11:55:46 AM1/27/12
to Korma
Hi,

I'm probably being dumb, but my application is running fine from the
repl but failing when I "lein run" or compile an uberjar and try and
run it.

I probably don't understand how the entity state is shared in the
namespace but I assumed it was like a global variable and should be
accessible to all functions within the namespace.

At the moment I have a main function which sets up the db connection
and calls a function to set up entities before calling the main work
function on some data selected:
(defn -main [user pass]
(defdb ...)
(setup entities)
(work-fn (select ids)))

The initial select works fine. It selects some ids from a table on
which to perform further selects on other tables.

A sub-fn of work-fn then does a select with a join i.e using a (with
someent)

This is works fine in the repl but with lein run I get an error:
Exception in thread "main" java.lang.RuntimeException:
java.lang.Exception: Entity used in relationship does not exist:
someent

Any ideas on what I'm doing wrong?

Many thanks,

Simon

Chris Granger

unread,
Jan 27, 2012, 12:51:34 PM1/27/12
to sqlk...@googlegroups.com
Can I see the code? Or a stripped down version of it? defentity creates to level vars just like def does, so the normal rules there would apply.

Cheers,
Chris.

Simon Holgate

unread,
Jan 29, 2012, 5:00:57 AM1/29/12
to Korma

Hi Chris,

I've put the code on GitHub.
https://github.com/simonholgate/psmsl_netcdf

It's very pre-alpha but you can hopefully see what I'm doing. Feedback
welcome of course. I'm pretty new to Clojure still :)

I'll try and produce a minimal application that reproduces this
behaviour anyway.

Cheers,

Simon

Chris Granger

unread,
Jan 29, 2012, 12:46:36 PM1/29/12
to sqlk...@googlegroups.com
Hey Simon,

Is there a specific reason you want to have (set-entities) define your entities and have your defdb be inside of -main? Typically creating top level definitions inside of functions isn't what you really want to do, and I believe it's what is causing your issues. 

Cheers,
Chris.

Simon Holgate

unread,
Jan 29, 2012, 5:51:49 PM1/29/12
to Korma
Hi Chris,

> Is there a specific reason you want to have (set-entities) define your
> entities and have your defdb be inside of -main? Typically creating top
> level definitions inside of functions isn't what you really want to do, and
> I believe it's what is causing your issues.

There was no reason apart from trying to keep the main function
reasonably short and keeping the table relations together. I'll try
putting them back into main and let you know how I get on.

Cheers,

Simon

Chris Granger

unread,
Jan 29, 2012, 6:42:02 PM1/29/12
to sqlk...@googlegroups.com
Ah, my suggestion isn't to have them in main, but to have them at the same level your defn's are:

(defdb ...)
(defentity stations ...)

(defn -main []
   (do-stuff))

Cheers,
Chris.

Simon Holgate

unread,
Jan 30, 2012, 1:05:22 PM1/30/12
to Korma
On Jan 29, 11:42 pm, Chris Granger <ibdk...@gmail.com> wrote:
> Ah, my suggestion isn't to have them in main, but to have them at the same
> level your defn's are:
>
> (defdb ...)
> (defentity stations ...)
>
> (defn -main []
> (do-stuff))

Oops, yep, I figured that out after running into some cyclical
dependencies then checking out another github project that's using
Korma (shrink-link).

I hadn't realised that the defentities would get evaluated without
calling them explicitly. That was the dumb bit I guess.

That has allowed me to lein run it but not from my uberjar.

I still haven't figured out defdb though. The reason I'd wrapped it in
-main was to pass username and password from the command line rather
than hardcoding it. i.e. (-main user pass db) or java -jar my.jar user
pass db

How should I handle that?

Cheers,

Simon

Chris Granger

unread,
Jan 31, 2012, 2:01:10 AM1/31/12
to sqlk...@googlegroups.com
Typically one would use a config file for that, but it's not unreasonable to do what you did and pulling the entities out was the more important part. 

Cheers,
Chris.

Simon Holgate

unread,
Feb 1, 2012, 7:08:15 AM2/1/12
to Korma
Hi Chris,

> Typically one would use a config file for that,

Good idea. Thanks.
Reply all
Reply to author
Forward
0 new messages