Cassandra Achilles:一对多的映射

时间:2016-11-15 13:44:20

标签: orm cassandra cassandra-3.0

我正在使用Cassandra 3.6和Achilles。我在Cassandra设计了下面的桌子。

CREATE TABLE userVehicles (
  userid text,
  name text static,
  surname text static,
  vehicleNum text,
  vehicleMake text,
  vehicleModel text,
  vehicleYear text,
  PRIMARY KEY (userid)
);

我会将很多车辆连接到单个用户,当我选择UserId时,我应该获得用户详细信息并且所有车辆都属于他。

如何在Achilles中映射?

更新表

CREATE TYPE Vehicle(
---------
)

然后在userVehicles表中

vehicleDetails LIST<FROZEN<Vehicle>>

尝试Achillies映射

@Table(keyspace="keyspace", table="userVehicles")
public class UserDetails{

    @PartitionKey(value = 1)
    private String userid ; 

    @Column
    private String name ;

    @Column
    private String surname;

    @Column
    private List<@Frozen Vehicle> vehicle;
}

@UDT(keyspace="keyspace", name="vehicle")
public class Vehicle {

    @Column
    private String vehicleNum ; 

    @NotNull
    @Column
    private String vehicleMake ;

    @Column
    private String vehicleModel ; 

    @NotNull
    @Column
    private String vehicleYear ;

}

@Configuration
@CompileTimeConfig(cassandraVersion = CassandraVersion.CASSANDRA_3_7)
public class AchillesConfiguration {

    @Autowired
    ManagerFactory managerFactory;

    @Bean
    public User_Manager userEntityManager(){
        return managerFactory.forUser(); 
    }

}

1 个答案:

答案 0 :(得分:0)

在上面的映射中更新了答案。对于嵌套表,这是你应该使用Achilles框架进入Cassandra的方式。