我正在使用Spring-data-cassandra 1.5.0M1。 我找不到在POJO中映射自定义/ UDT类型的方法。 我也看到了这篇文章Annotation for UDT by Spring data Cassandra。但我希望在新版本中添加对UDT类型的支持。 例如,我在Cassandra 3.7 DB中有Message UDT
CREATE TYPE MESSAGE (reply TEXT, time TIMESTAMP, user TEXT, patient UUID, status INT);
如何在我的实体POJO类中映射它?
@Table("conversations")
公共课堂对话{
@org.springframework.data.cassandra.mapping.PrimaryKey
private PrimaryKey primaryKey = new PrimaryKey();
@Column("status")
private Integer conversationStatus;
@Column("last_update")
private Date lastUpdate;
@Column("name")
private String name;
@Column("messages")
private List<Message> messages = new ArrayList<>();
public UUID getId() {
return primaryKey.id;
}
public void setId(UUID id) {
primaryKey.id = id;
}
public Integer getConversationStatus() {
return conversationStatus;
}
public void setConversationStatus(Integer conversationStatus) {
this.conversationStatus = conversationStatus;
}
public Date getLastUpdate() {
return lastUpdate;
}
public void setLastUpdate(Date lastUpdate) {
this.lastUpdate = lastUpdate;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Message> getMessages() {
return messages;
}
public void setMessages(List<Message> messages) {
this.messages = messages;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}
final Conversation rhs = (Conversation) obj;
return new EqualsBuilder()
.append(this.primaryKey.id, rhs.primaryKey.id)
.append(this.conversationStatus, rhs.conversationStatus)
.append(this.lastUpdate, rhs.lastUpdate)
.append(this.name, rhs.name)
.append(this.messages, rhs.messages)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder()
.append(primaryKey)
.append(conversationStatus)
.append(lastUpdate)
.append(name)
.append(messages)
.toHashCode();
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("primaryKey", primaryKey)
.append("conversationStatus", conversationStatus)
.append("lastUpdate", lastUpdate)
.append("name", name)
.append("messages", messages)
.toString();
}
public static final class PrimaryKey implements Serializable {
private static final long serialVersionUID = 4188262171705712608L;
@PrimaryKeyColumn(name = "id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
private UUID id;
public PrimaryKey() {
}
public PrimaryKey(UUID id) {
this.id = id;
}
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}
final PrimaryKey rhs = (PrimaryKey) obj;
return new EqualsBuilder()
.append(this.id, rhs.id)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder()
.append(id)
.toHashCode();
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("id", id)
.toString();
}
}
}
提前谢谢。