2015-11-05 60 views
0

我工作的Spring应用程序中插入记录使用Spring datastax卡桑德拉。 以下是我用来创建表格的脚本。缺少强制PRIMARY KEY部件版本

CREATE TABLE user(
      name text, 
      source text, 
      createddate timestamp, 
      version timestamp, 
      id timeuuid, 
      system text, 
      desc text, 
      PRIMARY KEY((name,source,createddate),version) 
); 

下面是我写的连接到卡桑德拉表的dto。

@PrimaryKeyClass 
public class User implements Serializable{ 

/** 
* 
*/ 
private static final long serialVersionUID = 1L; 
@PrimaryKeyColumn(ordinal = 0,type = PrimaryKeyType.PARTITIONED) 
private String name; 
@PrimaryKeyColumn(ordinal = 1,type = PrimaryKeyType.PARTITIONED) 
private String source; 
@PrimaryKeyColumn(ordinal = 2,type = PrimaryKeyType.PARTITIONED) 
private Date createddate; 
@PrimaryKeyColumn(ordinal = 3,type = PrimaryKeyType.CLUSTERED) 
private Date version; 
private UUID id; 
private String system; 
private String desc; 

但是,当我尝试插入记录,则抛出异常“com.datastax.driver.core.exceptions.InvalidQueryException:缺少强制PRIMARY KEY部件版本”。请帮我解决这个问题。提前致谢。

回答

0

1°)你检查version场不null

  • 创建@PrimaryKeyClass
  • 放注释专用的主键类:由于我从来没有使用过Spring数据卡珊德拉,我不知道,但通过看those annotations documentation也许你可以

    2°)您@PrimaryKeyColumn在它

  • 使用注释属性,在你的User类全新的主键类,标注为@PrimaryKey
+0

谢谢ThSlyu。由于所述版本feild为空。现在我为它分配了一个值,它工作正常。 – Pramod