Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating record from Clojure results into "Cannot cast com.aerospike.client.Bin to [Lcom.aerospike.client.Bin;" #19

Closed
andreiursan opened this issue Feb 21, 2015 · 2 comments

Comments

@andreiursan
Copy link

Trying to create aerospike records, using the client e.g. version [com.aerospike/aerospike-client "3.0.34"] or [com.aerospike/aerospike-client "3.0.20"]
results in the following error:
ClassCastException Cannot cast com.aerospike.client.Bin to [Lcom.aerospike.client.Bin; java.lang.Class.cast (Class.java:3133)

(ns todo-aerospike.domain.utils.db
  (:import [com.aerospike.client Bin AerospikeClient Key Record Info]
           [com.aerospike.client.cluster Node]
           [com.aerospike.client.policy WritePolicy]))

(def key-namespace "todo-aerospike")
(def write-policy (new WritePolicy))

(defn uuid []
  (str (java.util.UUID/randomUUID)))

(defn create [conn data]
  "[C]RUD creates a record  "
  (let [bin (new Bin (:column-name data) (:value data))
        key (new Key key-namespace (:set-name data) (uuid))]
        (println (.getClass bin)) ; for Debug
        (. conn put write-policy key bin)))

trying to create a record from the repl, results in the mentioned error

➜  todo-aerospike git:(master) ✗ lein repl
nREPL server started on port 53426 on host 127.0.0.1 - nrepl://127.0.0.1:53426
REPL-y 0.3.5, nREPL 0.2.6
Clojure 1.6.0
Java HotSpot(TM) 64-Bit Server VM 1.7.0_67-b01
    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

=> (in-ns 'todo-aerospike.domain.utils.db)
=> (def conn (new AerospikeClient "localhost" 3000))
=> (first (.getNodes conn))
#<Node BB976C89B270008 127.0.0.1:3000>
=>  (create conn { :column-name "test" :value "work you client" :set-name "test" })
com.aerospike.client.Bin

ClassCastException Cannot cast com.aerospike.client.Bin to [Lcom.aerospike.client.Bin;  java.lang.Class.cast (Class.java:3133)

and this is the stacktrace

java.lang.ClassCastException: Cannot cast com.aerospike.client.Bin to [Lcom.aerospike.client.Bin;
        at java.lang.Class.cast(Class.java:3133)
        at clojure.lang.Reflector.boxArg(Reflector.java:427)
        at clojure.lang.Reflector.boxArgs(Reflector.java:460)
        at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:58)
        at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28)
        at todo_aerospike.domain.utils.db$eval6145.invoke(form-init4786145880839548089.clj:1)
        at clojure.lang.Compiler.eval(Compiler.java:6703)
        at clojure.lang.Compiler.eval(Compiler.java:6666)
        at clojure.core$eval.invoke(core.clj:2927)
        at clojure.main$repl$read_eval_print__6625$fn__6628.invoke(main.clj:239)
        at clojure.main$repl$read_eval_print__6625.invoke(main.clj:239)
        at clojure.main$repl$fn__6634.invoke(main.clj:257)
        at clojure.main$repl.doInvoke(main.clj:257)
        at clojure.lang.RestFn.invoke(RestFn.java:1523)
        at clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__5548.invoke(interruptible_eval.clj:67)
        at clojure.lang.AFn.applyToHelper(AFn.java:152)
        at clojure.lang.AFn.applyTo(AFn.java:144)
        at clojure.core$apply.invoke(core.clj:624)
        at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1862)
        at clojure.lang.RestFn.invoke(RestFn.java:425)
        at clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke(interruptible_eval.clj:51)
        at clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__5590$fn__5593.invoke(interruptible_eval.clj:183)
        at clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__5583.invoke(interruptible_eval.clj:152)
        at clojure.lang.AFn.run(AFn.java:22)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)

I want to creat an aerospike todo app to showcase the client API.
here is the github repo https://github.com/andreiursan/todo-aerospike

@andreiursan andreiursan changed the title Creating record from Clojure results into " Cannot cast com.aerospike.client.Bin to [Lcom.aerospike.client.Bin; " Creating record from Clojure results into "Cannot cast com.aerospike.client.Bin to [Lcom.aerospike.client.Bin;" Feb 21, 2015
@puredanger
Copy link

[Lcom.aerospike.client.Bin; is the Java class name for an array of Bin. In (. conn put write-policy key bin), maybe the last thing takes Bin... in the Java API? If so, Java varargs look like an array to the JVM and you'll need this in Clojure:
(. conn put write-policy key (into-array [bin]))

@andreiursan
Copy link
Author

@puredanger That fixed my issue.
And I learned something new, feeling great, thank you!

the fixed function is:

(defn create [conn data]
  "[C]RUD creates a record"
  (let [bin (new Bin (:column-name data) (:value data))
        key (new Key key-namespace (:set-name data) (uuid))]
        (. conn put write-policy key (into-array [bin]))))

BrianNichols pushed a commit that referenced this issue May 16, 2019
ijusti pushed a commit to ijusti/aerospike-client-java that referenced this issue Mar 28, 2023
ijusti pushed a commit to ijusti/aerospike-client-java that referenced this issue Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants