Mapper and PreparedStatements

100 views
Skip to first unread message

se...@zaius.com

unread,
Apr 25, 2018, 11:48:27 AM4/25/18
to DataStax Java Driver for Apache Cassandra User Mailing List
Hello,

We are using the Mapper (2.1.7) to map entities to tables.  Nice abstraction however it appears that under the covers the framework is generating the same prepared statement over and over instead of caching them.  Seeing a lot of warning log messages:

Re-preparing already prepared query .... Please note that preparing the same query more than once is generally an anti-pattern and will likely affect performance. Consider preparing the statement only once.

I didn't see any options that I can set to direct the Mapper to cache prepared statements.  Is there anything I should be doing in order to change this behavior?

Thanks in advance,
Sean

Andy Tolbert

unread,
Apr 25, 2018, 11:54:14 AM4/25/18
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi Sean,

Is it possible that you are creating multiple Mapper instances instead of reusing the same one?    The mapper itself should only prepare statements when you call the associated Mapper.save,get,delete queries for the first time, as each Mapper instance has its own cache of prepared statements.

Thanks,
Andy

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-user+unsubscribe@lists.datastax.com.

se...@zaius.com

unread,
Apr 25, 2018, 12:01:59 PM4/25/18
to DataStax Java Driver for Apache Cassandra User Mailing List
If the mapper instances are internally keeping a cache then we must be. I am caching the mappers statically but this is all being used inside a storm topology usage inside the bolts might be constructing the same mapper multiple time.  Appreciate the quick response Andy.

Thanks
Sean
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

se...@zaius.com

unread,
Apr 25, 2018, 12:13:27 PM4/25/18
to DataStax Java Driver for Apache Cassandra User Mailing List
Upon further inspection we are using the MappingManager to fetch the mappers by class.  There is a single static reference to the MappingManager setup once for the JVM, and looking at the source the Mapper instances are cached by class.  Guess I'm going to need to go down the rabbit hole.  Some strangeness when using this in a storm topo.

Sean

On Wednesday, April 25, 2018 at 11:54:14 AM UTC-4, Andrew Tolbert wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

Reply all
Reply to author
Forward
0 new messages