尝试为实体创建 DAO 并将 id 指定为自动增量时,这似乎是一个非常奇怪的问题。
我的代码:
private static Entity addSearch(Schema schema) {
Entity search = schema.addEntity("Search");
search.addIdProperty().primaryKey().autoincrement();
search.addStringProperty("title").notNull();
search.addIntProperty("type");
search.addIntProperty("timestamp");
return search;
}
和生成的 DAO 文件:
public class Search {
private Long id;
/** Not-null value. */
private String title;
private Integer type;
private Integer timestamp;
// KEEP FIELDS - put your custom fields here
// KEEP FIELDS END
public SearchData() {
}
public SearchData(Long id) {
this.id = id;
}
public SearchData(Long id, String title, Integer type, Integer timestamp) {
this.id = id;
this.title = title;
this.type = type;
this.timestamp = timestamp;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
/** Not-null value. */
public String getTitle() {
return title;
}
/** Not-null value; ensure this value is available before it is saved to the database. */
public void setTitle(String title) {
this.title = title;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Integer getTimestamp() {
return timestamp;
}
public void setTimestamp(Integer timestamp) {
this.timestamp = timestamp;
}
// KEEP METHODS - put your custom methods here
// KEEP METHODS END
}
既然我已将 id 指定为自动增量,为什么它会生成带有 id 参数的构造函数?这就是自动增量的点,因此您不必自己指定它。
有什么建议么?