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);
}
答案 0 :(得分:1)
不幸的是,您今天无法使用驱动程序或其对象映射API执行此操作。今天开设了一个悬而未决的问题(JAVA-722)来处理这个和其他与映射相关的不足之处(在该问题中相关的相关问题),将在驱动程序的下一个版本(2.1.6)中介绍。
通过Achilles来查看支持此内容的Type Transformer也许值得一看。