Re: [scalikejdbc-users-group:697] Batch API complains "No implicits arguments of type: Factory[Int, C_[Int]]"

43 views
Skip to first unread message

Kazuhiro Sera

unread,
Jan 6, 2019, 4:42:09 PM1/6/19
to Sandeep Thandassery, ScalikeJDBC Users Group
I was not able to reproduce your situation.

---

scala> :paste
// Entering paste mode (ctrl-D to finish)

import scalikejdbc._
Class.forName("org.h2.Driver")
ConnectionPool.singleton("jdbc:h2:mem:hello", "user", "pass")
DB localTx { implicit session =>
sql"create table emp (id serial not null primary key, name
varchar(64))".execute.apply()
val batchParams: Seq[Seq[Any]] = (2001 to 3000).map(i => Seq(i, "name" + i))
sql"insert into emp (id, name) values (?, ?)".batch(batchParams: _*).apply()
}

// Exiting paste mode, now interpreting.

06:40:51.832 [run-main-0] DEBUG scalikejdbc.ConnectionPool$ -
Registered connection pool : ConnectionPool(url:jdbc:h2:mem:hello,
user:user) using factory : <default>
06:40:51.833 [run-main-0] DEBUG scalikejdbc.ConnectionPool$ -
Registered singleton connection pool :
ConnectionPool(url:jdbc:h2:mem:hello, user:user)
06:40:52.094 [run-main-0] DEBUG scalikejdbc.StatementExecutor$$anon$1
- SQL execution completed

[SQL Execution]
create table emp (id serial not null primary key, name varchar(64)); (7 ms)

[Stack Trace]
...
$line2.$read$$iw$$iw$.$anonfun$res0$1(<console>:17)
scalikejdbc.DBConnection.$anonfun$localTx$3(DBConnection.scala:335)
scalikejdbc.DBConnection.rollbackIfThrowable(DBConnection.scala:300)
scalikejdbc.DBConnection.localTx(DBConnection.scala:329)
scalikejdbc.DBConnection.localTx$(DBConnection.scala:324)
scalikejdbc.DB.localTx(DB.scala:60)
scalikejdbc.DB$.localTx(DB.scala:261)
$line2.$read$$iw$$iw$.<init>(<console>:16)
$line2.$read$$iw$$iw$.<clinit>(<console>)
$line2.$eval$.$print$lzycompute(<console>:7)
$line2.$eval$.$print(<console>:6)
$line2.$eval.$print(<console>)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
...

06:40:52.265 [run-main-0] DEBUG scalikejdbc.StatementExecutor$$anon$1
- SQL execution completed

[SQL Execution]
insert into emp (id, name) values (2001, 'name2001');
insert into emp (id, name) values (2002, 'name2002');
insert into emp (id, name) values (2003, 'name2003');
insert into emp (id, name) values (2004, 'name2004');
insert into emp (id, name) values (2005, 'name2005');
insert into emp (id, name) values (2006, 'name2006');
insert into emp (id, name) values (2007, 'name2007');
insert into emp (id, name) values (2008, 'name2008');
insert into emp (id, name) values (2009, 'name2009');
insert into emp (id, name) values (2010, 'name2010');
insert into emp (id, name) values (2011, 'name2011');
insert into emp (id, name) values (2012, 'name2012');
insert into emp (id, name) values (2013, 'name2013');
insert into emp (id, name) values (2014, 'name2014');
insert into emp (id, name) values (2015, 'name2015');
insert into emp (id, name) values (2016, 'name2016');
insert into emp (id, name) values (2017, 'name2017');
insert into emp (id, name) values (2018, 'name2018');
insert into emp (id, name) values (2019, 'name2019');
insert into emp (id, name) values (2020, 'name2020');
... (total: 1000 times); (96 ms)

[Stack Trace]
...
$line2.$read$$iw$$iw$.$anonfun$res0$1(<console>:19)
scalikejdbc.DBConnection.$anonfun$localTx$3(DBConnection.scala:335)
scalikejdbc.DBConnection.rollbackIfThrowable(DBConnection.scala:300)
scalikejdbc.DBConnection.localTx(DBConnection.scala:329)
scalikejdbc.DBConnection.localTx$(DBConnection.scala:324)
scalikejdbc.DB.localTx(DB.scala:60)
scalikejdbc.DB$.localTx(DB.scala:261)
$line2.$read$$iw$$iw$.<init>(<console>:16)
$line2.$read$$iw$$iw$.<clinit>(<console>)
$line2.$eval$.$print$lzycompute(<console>:7)
$line2.$eval$.$print(<console>:6)
$line2.$eval.$print(<console>)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
...

import scalikejdbc._
res0: scala.collection.immutable.IndexedSeq[Int] = Vector(1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,...

scala>

On Sat, Jan 5, 2019 at 4:59 AM Sandeep Thandassery
<sandeep.t...@gmail.com> wrote:
>
> On using Batch API like below, apply method complains "No implicits arguments of type: Factory[Int, C_[Int]]". How can I get rid of this error?
>
>
> DBs.setupAll()
>
> DB localTx { implicit session =>
> val batchParams: Seq[Seq[Any]] = (2001 to 3000).map(i => Seq(i, "name" + i))
> sql"insert into emp (id, name) values (?, ?)".batch(batchParams: _*).apply()
> }
>
> --
> You received this message because you are subscribed to the Google Groups "ScalikeJDBC Users Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to scalikejdbc-users...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Sandeep Thandassery

unread,
Jan 7, 2019, 11:08:17 AM1/7/19
to ScalikeJDBC Users Group
I see the error in my IDE. I am using IntelliJ IDEA.

> To unsubscribe from this group and stop receiving emails from it, send an email to scalikejdbc-users-group+unsub...@googlegroups.com.

bmu...@slack-corp.com

unread,
Jan 7, 2019, 12:21:21 PM1/7/19
to ScalikeJDBC Users Group
I'm seeing the same error with Intellij 2018.2.7. Interestingly, the code compiles correctly via CLI (pants), so it must be specific to Intellij.

bmu...@slack-corp.com

unread,
Jan 7, 2019, 12:30:59 PM1/7/19
to ScalikeJDBC Users Group
Oh, look at the method signature of apply:

def apply[C[_]]()(implicit session: DBSession, factory: Factory[Long, C[Long]]): C[Long]

Send a type parameter to apply, example: 

.apply[Seq]()

Works without a type parameter only due to type erasure.
Reply all
Reply to author
Forward
0 new messages