Datastax: Re-preparing already prepared query warning

3.7k Views Asked by At

I have this code

    UUID notUuid = UUIDs.timeBased();        
    PreparedStatement   pstmt           = cqlSession.prepare("INSERT INTO mytable(userId, notifId, notification, time, read, deleted) VALUES(?, ?, ?, ?, ?, ?)");
    BoundStatement      boundStatement  = new BoundStatement(pstmt);
    cqlSession.execute(boundStatement.bind(userId, notUuid, notfMsg, System.currentTimeMillis(), MigificConstants.UNREAD, "false"));

when i run this code, in the log it shows

Re-preparing already prepared query INSERT INTO mytable(userId, notifId, notification, time, read, deleted) VALUES(?, ?, ?, ?, ?, ?). 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.
1

There are 1 best solutions below

2
On

Is this code part of a method that is called multiple times?

Statements need only be prepared once per Cluster instance, you should do it in some initialization part of your application.