Last active
August 29, 2015 14:05
-
-
Save domdorn/fb504a510ffda470991b to your computer and use it in GitHub Desktop.
Problem with jOOQ and Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package helpers; | |
import org.jooq.DSLContext; | |
import java.util.Collection; | |
/** | |
* | |
*/ | |
public class DSLWrapper { | |
private final DSLContext context; | |
public DSLWrapper(final DSLContext context) { | |
this.context = context; | |
} | |
public int execute(String sql, Collection<? extends Object> arguments) { | |
return context.execute(sql, arguments.toArray()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[info] Compiling 1 Scala source and 1 Java source to /home/domdorn/lyrix/lyrix_php/playlyrix/target/scala-2.11/classes... | |
[error] /home/domdorn/lyrix/lyrix_php/playlyrix/app/controllers/Security.scala:54: overloaded method value execute with alternatives: | |
[error] (x$1: String,x$2: org.jooq.QueryPart*)Int <and> | |
[error] (x$1: String,x$2: Object*)Int | |
[error] cannot be applied to (String, Long, String) | |
[error] e.execute(sql, userId, uuid) | |
[error] ^ | |
[error] one error found | |
[error] (compile:compile) Compilation failed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val userId = 1L | |
val uuid = UUID.randomUUID().toString.replace("-", "") | |
val sql = "INSERT INTO sometable (userId, hash) VALUES (?, ?);" | |
DB.withTransaction(conn => { | |
val e = DSL.using(conn, SQLDialect.POSTGRES) | |
e.execute(sql, userId, uuid) // does not work | |
// e.execute(sql, List(userId, uuid) : _*) // does not work either | |
}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val e = DSL.using(conn, SQLDialect.POSTGRES) | |
val l : java.util.ArrayList[Object] = new java.util.ArrayList[Object]() | |
l.add(java.lang.Long.valueOf(userId)) | |
l.add(uuid) | |
new DSLWrapper(e).execute(sql, l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@lukaseder: Yes, that works: