I have multiple PreparedStatements which I create during bean initialization just once with current setup of single keyspace, but I'm now trying to work with multiple keyspaces while table schema remains the same as following:
//session1 is from connecting to keyspace1
//while session2 to keyspace2
PreparedStatements ps = session1.prepare(sameStmt);
PreparesStatement ps1 = session2.prepare(sameStmt);
What I'm trying to figure out is, if there's difference between two besides being two different objects and from two different keyspaces considering the query string is same for both? The thing I want to achieve is to be able to create the PreparedStatement only once irrespective of keyspace if possible. Any suggestions?
This is not something that Cassandra allows by design. Even if the table schema is the same between the tables in the two keyspaces, there is no way to be sure of this. For safety, Cassandra generates different prepared statements ids and therefore they are treated as different prepared statements.