Is there a way to use our types (classes we provide) in the the collection types that we provide to the DataStax Java Driver through the BoundStatement.setSet(..)
method without using User Defined Types? Perhaps with the Object Mapping API?
And if so, when we create the table what should we use for the type in the SET
(in other words: SET<????>
)?
We're using the DataStax Java Driver v2.1.5 connected to DSE v4.6.0 (Cassandra 2.0.11.83).
Here's an example to illustrate:
CREATE TABLE teams (uid TEXT PRIMARY KEY, players SET<????>);
Our Type:
public class Player {
private String name;
public Player(String name) { this.name = name; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
Test:
public void testSets(){
Set<Player> players = new HashSet<>();
players.add(new Player("Nick"));
players.add(new Player("Paul"));
players.add(new Player("Scott"));
PreparedStatement statement = session.prepare("INSERT INTO teams (uid, players) values (?,?);");
BoundStatement boundStatement = new BoundStatement(statement);
boundStatement.setString("uid", ...);
boundStatement.setSet("players", players);
session.execute(boundStatement);
}