这是我的模式生成代码:
Schema schema = new Schema(VERSION, "com.example.dao");
Entity player = schema.addEntity("Player");
Property playerIdProperty = player.addStringProperty("id").primaryKey().getProperty();
player.addStringProperty("name").notNull();
player.addStringProperty("created_at");
player.addStringProperty("updated_at");
Entity match = schema.addEntity("Match");
match.addStringProperty("id").primaryKey();
match.addIntProperty("score1");
match.addIntProperty("score2");
match.addStringProperty("created_at");
match.addStringProperty("updated_at");
match.addToOne(player, playerIdProperty, "dp1");
match.addToOne(player, playerIdProperty, "dp2");
match.addToOne(player, playerIdProperty, "op1");
match.addToOne(player, playerIdProperty, "op2");
new DaoGenerator().generateAll(schema, "app/src-gen");
这是它生成的内容:
public class MatchDao extends AbstractDao<Match, String> {
public static final String TABLENAME = "MATCH";
/**
* Properties of entity Match.<br/>
* Can be used for QueryBuilder and for referencing column names.
*/
public static class Properties {
public final static Property Id = new Property(0, String.class, "id", true, "ID");
public final static Property Score1 = new Property(1, Integer.class, "score1", false, "SCORE1");
public final static Property Score2 = new Property(2, Integer.class, "score2", false, "SCORE2");
public final static Property Created_at = new Property(3, String.class, "created_at", false, "CREATED_AT");
public final static Property Updated_at = new Property(4, String.class, "updated_at", false, "UPDATED_AT");
public final static Property Id = new Property(5, String.class, "id", true, "ID");
};
正如您所看到的,在MatchDao中有两个名为“Id”的属性。我需要做的是生成两个表,主键分别为字符串(因为远程数据库的要求)和4个外键(每场比赛有4个玩家)。
问题是:为什么“Id”属性会重复,并且如何避免它?谢谢提前。