I am using DataStax driver to connect to Cassandra database from my Scala application. The driver comes with com.datastax.driver.mapping to map the database table to the corresponding entity class.
I intend to use the mapper like this:
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()
}
}
The Entity User
is mapped to the database using @Table
annotation like this:
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
}
I receive a error message saying No getter or setter method found for Field UserId.
I found an example java code for the similar annotation example and it works fine:
@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;
My doubt, is there no way to use the @Table
annotation in scala code? If yes, where did i go wrong?
PS: I tried implementing the case class user without body and providing the annotations on top of parameters. Even that gave the same error message.