我有这段代码
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 建立: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();