我正在使用greendao在Android上维护SQL数据库.现在我面临生成具有两列作为主键的实体的问题.要清楚我有column1和column2它们都是Long值,它们一起形成一个主键.
我试图将其建模为
@Index(unique = true)
private Long column1, column2
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我在尝试插入时遇到了独特的约束失败,当尝试inserOrReplace时,它只是替换了基于column1的id.
我通过定义这样的实体解决了它:
@Id(autoincrement = true) //I totally don't care about value of this field
private Long idLocal;
@Index //this are 2 columns that I use as primary key
private Long column1id, column2id;
Run Code Online (Sandbox Code Playgroud)
我知道这可能不是最佳解决方案,但它正在发挥作用.然而,赏金仍然是开放的,我会把它给任何能给我更好解决方案的人.