cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carlos Scheidecker <nando....@gmail.com>
Subject How to map a set<text> field?
Date Sun, 21 Sep 2014 03:28:10 GMT
Hello all,

I have the following table:

CREATE TABLE userprincipal (
  userid timeuuid,
  username varchar,
  hashedpassword blob,
  authorities set<text>,
  accountnonexpired boolean,
  accountnonlocked boolean,
  credentialsnonexpired boolean,
  enabled boolean,
  PRIMARY KEY(username)
);

Now, I have an UserPrincipalObject to which Authorities ia a HashSet of
UserAuthority Spring objects. If the system does the setting through that
object, I update my own set of Strings called sAuthorities.

On the database I save the sAuthorities which is what I map. But on the
object on the memory I mape the set of UserAuthorities

My UserPrincipalObject is as follows:

@Table(name = "userprincipal")
public class UserPrincipal implements UserDetails, CredentialsContainer,
Cloneable {

@Transient
private static final long serialVersionUID = 1L;

@PartitionKey
@Column(name = "username")
private String userName;

@Column(name = "userid")
private UUID userID;

@Column(name = "hashedpassword")
private ByteBuffer hashedPassword;

@Column(name = "sauthorities")
private Set<String> sAuthorities = new HashSet<String>();
 @Transient
@FrozenValue
Set<UserAuthority> authorities = new HashSet<UserAuthority>();

@Column(name = "accountnonexpired")
private boolean accountNonExpired;

@Column(name = "accountnonlocked")
private boolean accountNonLocked;

@Column(name = "credentialsnonexpired")
private boolean credentialsNonExpired;

@Column(name = "enabled")
private boolean enabled;

The setters for both Authorities list is as follows:

Now, note that the set for sAuthorities updates the authorities variable
which is a Set<UserAuthority>

And that the set for authorities updates the Set<String> sAuthority with is
what gets persisted to the table.

So  @Column(name = "sauthorities")
private Set<String> sAuthorities = new HashSet<String>();

Also authorities is @Transient annotated.


public Set<String> getsAuthorities() {
return sAuthorities;
}

public void setsAuthorities(Set<String> sAuthorities) {
this.sAuthorities = sAuthorities;
this.authorities = new HashSet<UserAuthority>();
UserAuthority auxAuthor;
for (String a : sAuthorities) {
auxAuthor = new UserAuthority(a);
this.authorities.add(auxAuthor);
}
}

@Override
public Set<UserAuthority> getAuthorities() {
return this.authorities;
}

public void setAuthorities(Set<UserAuthority> authorities) {
this.authorities = authorities;
this.sAuthorities = new HashSet<String>();
for (UserAuthority a : this.authorities) {
this.sAuthorities.add(a.getAuthority());
}
}


However, when I create the mapper I get the following error:

Exception in thread "main" java.lang.IllegalArgumentException: Cannot find
matching getter and setter for field 'sAuthorities'
at
com.datastax.driver.mapping.ReflectionMapper$ReflectionFactory.createColumnMapper(ReflectionMapper.java:375)
at
com.datastax.driver.mapping.AnnotationParser.convert(AnnotationParser.java:148)
at
com.datastax.driver.mapping.AnnotationParser.parseEntity(AnnotationParser.java:100)
at
com.datastax.driver.mapping.MappingManager.getMapper(MappingManager.java:119)
at com.datastax.driver.mapping.MappingManager.mapper(MappingManager.java:76)

Now, note that sAuthorities is properly annotated:

@Column(name = "sauthorities")
private Set<String> sAuthorities = new HashSet<String>();

My mapper code is as follows:

MappingManager manager = new MappingManager(session);
Mapper<UserPrincipal> mapper = manager.mapper(UserPrincipal.class);
mapper.save(principal);

What is going wrong? Do I have to have a special annotation for Set<text>
 because I could not find one looking at the source code nor the manual.
Yes for UDTs you have that. Do I have to put that inside an UDT?

Thanks.

Mime
View raw message