scala类的注释使用映射器

时间:2016-12-24 05:21:15

标签: scala cassandra datastax datastax-java-driver mapper

我正在使用DataStax驱动程序从我的Scala应用程序连接到Cassandra数据库。驱动程序附带com.datastax.driver.mapping以将数据库表映射到相应的实体类。

我打算像这样使用映射器:

def SelectOperationUsingMapper()={
try{
  val session = cluster.connect()
  val manager = new MappingManager(session);
  val mapper = manager.mapper(classOf[User])
  val result= mapper.get("@ned")
  print(result.Name)
}
finally{
  cluster.close()
}

}

使用User注释将实体@Table映射到数据库,如下所示:

abstract class BusinessEntity

@Table(keyspace="MySpace", name="User")
case class User(userId:String, emailId:String, name:String, description:String, password:String, country:String, joinedDate:Date) extends BusinessEntity{
  @PartitionKey
  @Column(name = "UserId")
  val UserId= userId
  @Column(name = "EmailId")
  val EmailId= emailId
  @Column(name = "Name")
  val Name= name
  @Column(name = "Description")
  val Description= description
  @Column(name = "Password")
  val Password= password
  @Column(name = "Country")
  val Country= country
  @Column(name = "JoinedDate")
  val JoinedDate= joinedDate
}

我收到一条错误消息,指出没有为Field UserId找到getter或setter方法。

我找到了类似注释示例的示例java代码,它工作正常:

 @Table(keyspace = "accounts", name = "users")
public class User {  
    private int id;
    @Column( name = "account_id" )
    private int accountId;
    private String name;
    @Column( name = "creation_date" )
    private Date creationDate;

我怀疑,是否有办法在scala代码中使用@Table注释?如果是的话,我哪里出错了?

  

PS:我尝试在没有body的情况下实现case类用户   在参数之上提供注释。即便如此   同样的错误信息。

0 个答案:

没有答案