GreenDao错误:目标实体没有主键,但我们需要ToMany

时间:2015-10-23 10:30:49

标签: android greendao greendao-generator

我有这段代码

    Entity pokemonSpecies = schema.addEntity("PokemonSpecies");
    pokemonSpecies.setTableName("pokemon_species");
    pokemonSpecies.addIdProperty();
    pokemonSpecies.addStringProperty("identifier").notNull();
    pokemonSpecies.addIntProperty("genderRate").notNull();
    pokemonSpecies.addIntProperty("captureRate").notNull();
    pokemonSpecies.addIntProperty("baseHappiness").notNull();
    pokemonSpecies.addBooleanProperty("isBaby").notNull();
    pokemonSpecies.addIntProperty("hatchCounter").notNull();
    pokemonSpecies.addBooleanProperty("hasGenderDifferences").notNull();
    pokemonSpecies.addBooleanProperty("formsSwitchable").notNull();
    pokemonSpecies.addIntProperty("order").notNull();
    pokemonSpecies.addIntProperty("conquestOrder");

    Entity conquestWarriorTransformation = schema.addEntity("ConquestWarriorTransformation");
    conquestWarriorTransformation.setTableName("conquest_warrior_transformation");
    conquestWarriorTransformation.addBooleanProperty("isAutomatic").notNull();
    conquestWarriorTransformation.addIntProperty("requiredLink");
    conquestWarriorTransformation.addIntProperty("femaleWarlord");
    conquestWarriorTransformation.addIntProperty("pokemonCount");
    conquestWarriorTransformation.addIntProperty("warriorCount");
    Property conquestWarriorTransformationRankId = conquestWarriorTransformation.addLongProperty("transformedWarriorRankId").primaryKey().notNull().getProperty();

    Entity conquestTransformationPokemon = schema.addEntity("ConquestTransformationPokemon");
    conquestTransformationPokemon.setTableName("conquest_transformation_pokemon");
    Property conquestTransformationPokemonTransformationId = conquestTransformationPokemon.addLongProperty("transformationId").notNull().getProperty();
    Property conquestTransformationPokemonSpeciesId = conquestTransformationPokemon.addLongProperty("pokemonSpeciesId").notNull().getProperty();
    conquestTransformationPokemon.addToOne(conquestWarriorTransformation, conquestTransformationPokemonTransformationId);
    conquestTransformationPokemon.addToOne(pokemonSpecies, conquestTransformationPokemonSpeciesId);
    conquestWarriorTransformation.addToMany(pokemonSpecies, conquestTransformationPokemon, conquestTransformationPokemonTransformationId, conquestTransformationPokemonSpeciesId).setName("pokemonSpecies");
    pokemonSpecies.addToMany(conquestWarriorTransformation, conquestTransformationPokemon, conquestTransformationPokemonSpeciesId, conquestTransformationPokemonTransformationId).setName("conquestWarriorTransformations");

我尝试与PokemonSpecies和ConquestWarriorTransformation建立n:m关系,但编译器给了我这个错误:

java.lang.RuntimeException: Target entity has no primary key, but we need it for ToMany 'conquestWarriorTransformations' from PokemonSpecies to ConquestWarriorTransformation
at de.greenrobot.daogenerator.ToManyWithJoinEntity.init2ndPass(ToManyWithJoinEntity.java:56)
at de.greenrobot.daogenerator.Entity.init2ndPass(Entity.java:499)
at de.greenrobot.daogenerator.Schema.init2ndPass(Schema.java:179)
at de.greenrobot.daogenerator.DaoGenerator.generateAll(DaoGenerator.java:92)
at de.greenrobot.daogenerator.DaoGenerator.generateAll(DaoGenerator.java:81)
at GreenDaoGenerator.main(GreenDaoGenerator.java:15)

它没有意义,因为我在ConquestWarriorTransformation中有一个主键:

Property conquestWarriorTransformationRankId = conquestWarriorTransformation.addLongProperty("transformedWarriorRankId").primaryKey().notNull().getProperty();

0 个答案:

没有答案