1

I'm trying to use spring-data-cassandra (1.1.2.RELEASE) and I'm running into an issue with the lack of embeddable type mapping in JPA parlance.

I have an entity class like this:

@Table
public class Customer {

    private UUID id;
    private String name;
    private Address address;

    public UUID getId() {
        return id;
    }

    public void setId(UUID id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

 }

and the embeddable Address class:

public class Address {

    private String address;
    private String city;
    private String state;
    private String zip;

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }

}

My cassandra table:

create table customer ( 
    id uuid primary key, 
    name text, 
    address text, 
    city text, 
    state text, 
    zip text
);

I want the properties of Address to be mapped into the containing entity, I don't want a separate table for addresses. In JPA, I believe I'd use an @Embeddable annotation. Is there some similar construct in spring-data-cassandra?

4

1 回答 1

2

spring-data-cassandra 尚不支持可嵌入类型。可以在DATACASS-167获得功能请求。

唯一可能嵌入的实体部分是主键。如果您的主键由多个字段组成,您可以将这些字段外部化到一个单独的类中,然后将其与@PrimaryKey注释一起使用。

评论.java

@Table("comments")
public class Comment {

    @PrimaryKey
    private CommentKey pk;

    private String text;
}

注释键.java

@PrimaryKeyClass
public class CommentKey implements Serializable {

    private static final long serialVersionUID = -7871651389236401141L;

    @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED)
    private String author;

    @PrimaryKeyColumn(ordinal = 1)
    private String company;
}

HTH,马克

于 2015-05-28T18:56:35.323 回答