我正在使用Kundera(3.13)在Java(8)中为Cassandra(3.11)数据库建模,并且被卡在使用复合分区键的表上。 键空间/表的定义是这样的:
CREATE KEYSPACE test
WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 3};
CREATE TABLE test.timeseriesdata (
asset_id TEXT,
time_series_definition_id TEXT,
business_date_year INT,
business_date DATE,
system_time TIMESTAMP,
values_blob MAP<TEXT, BLOB>,
values_boolean MAP<TEXT, BOOLEAN>,
values_double MAP<TEXT, DOUBLE>,
values_int MAP<TEXT, INT>,
values_text MAP<TEXT, TEXT>,
values_timestamp MAP<TEXT, TIMESTAMP>,
PRIMARY KEY ((asset_id, time_series_definition_id, business_date_year), business_date, system_time)
) WITH CLUSTERING ORDER BY (business_date DESC, system_time DESC);
Kundera实体看起来像这样:
@Embeddable
public class TimeSeriesDataPartitionKey implements Serializable {
@Column(name = "asset_id")
private String assetId;
@Column(name = "time_series_definition_id")
private String timeSeriesDefinitionId;
@Column(name = "business_date_year")
private Integer businessDateYear;
}
@Embeddable
public class TimeSeriesDataPrimaryKey implements Serializable {
@Embedded
private TimeSeriesDataPartitionKey key;
@Column(name = "business_date")
@Temporal(TemporalType.DATE)
private Date businessDate;
@Column(name = "system_time")
@Temporal(TemporalType.TIMESTAMP)
private Date systemTime;
}
@Entity
@Table(name = "timeseriesdata", schema = "test@cassandra_pu")
public class TimeSeriesDataEntity {
@EmbeddedId
private TimeSeriesDataPrimaryKey key;
@ElementCollection
@Column(name = "values_blob")
private Map<String, byte[]> valuesBlob = new HashMap<>();
@ElementCollection
@Column(name = "values_boolean")
private Map<String, Boolean> valuesBoolean = new HashMap<>();
@ElementCollection
@Column(name = "values_double")
private Map<String, Double> valuesDouble = new HashMap<>();
@ElementCollection
@Column(name = "values_int")
private Map<String, Integer> valuesInt = new HashMap<>();
@ElementCollection
@Column(name = "values_text")
private Map<String, String> valuesText = new HashMap<>();
@ElementCollection
@Column(name = "values_timestamp")
@Temporal(TemporalType.TIMESTAMP)
private Map<String, Date> valuesTimestamp = new HashMap<>();
}
我正在使用<property name="kundera.ddl.auto.prepare" value="validate"/>
在persistence.xml文件中,以确保实体建模正确。
当我运行一些代码尝试添加一些数据时,它失败并显示消息
com.impetus.kundera.configure.schema.SchemaGenerationException:com.impetus.kundera.configure.schema.SchemaGenerationException:模式不匹配!验证失败。参见上表以了解不匹配情况
这里a link到diffchecker表中,在该表中粘贴了我收到的架构不匹配消息。另外,在像我一样对Kundera实体建模时,我尝试使用here,here和here中的资源。 我只是无法理解如何做,我给我的老师发了邮件,他告诉我展平模型,因为制作复合钥匙是不可能的,而现在我的头脑更加模糊。
编辑
如果我使用<property name="kundera.ddl.auto.prepare" value="create"/>
然后代码运行,如果我生成了sql备份,它看起来像这样
CREATE TABLE test.timeseriesdata (
asset_id TEXT,
time_series_definition_id TEXT,
business_date_year INT,
business_date TIMESTAMP,
system_time TIMESTAMP,
values_blob MAP<TEXT, BLOB>,
values_boolean MAP<TEXT, BOOLEAN>,
values_double MAP<TEXT, DOUBLE>,
values_int MAP<TEXT, INT>,
values_text MAP<TEXT, TEXT>,
values_timestamp MAP<TEXT, TIMESTAMP>,
PRIMARY KEY ((asset_id, time_series_definition_id, business_date_year), business_date, system_time)
);
所以区别是business_date type is TIMESTAMP not DATE
和WITH CLUSTERING ORDER BY
丢失了。
所以现在的问题是:cassandra DATE应该使用哪种Java类型?为什么缺少聚类顺序?