问题描述
房间
我有这样的关系 拼图->有一个->对话->有很多->对话行
我遵循了 https://developer.android.com/training/data-storage/room/relationships#kotlin 但仍然无法正常工作
这些似乎与错误有关:
错误:在com.example.puzzleherexamenandroid.data.room.databaseModels.DialogueWithLinesDatabase中找不到子实体列puzzleDialogueId
。
尝试了以下构造函数,但它们不匹配: PuzzleWithDialogueDatabase(com.example.puzzleherexamenandroid.data.room.databaseModels.PuzzleDatabase,com.example.puzzleherexamenandroid.data.room.databaseModels.DialogueWithLinesDatabase)-> [param:puzzle->匹配字段:puzzle,param:dialogueWithLines->匹配字段:unmatched] C:\ Users \ Jasper \ StudioProjects \ PuzzleHerexamenAndroid \ app \ build \ tmp \ kapt3 \ stubs \ debug \ com \ example \ puzzleherexamenandroid \ data \ room \ databaseModels \ PuzzleWithDialogueDatabase.java:9:错误:找不到以下设置器字段。
PuzzleDatabaseDao.java:12:错误:参数的类型必须是带有@Entity或其集合/数组注释的类。
java.util.List
这些是我的实体
@Entity(tableName = "puzzle_table")
@Parcelize
data class PuzzleDatabase (
@PrimaryKey
val puzzleId: Int,val title: String,val prompt: String,val answer: String
): Parcelable
@Entity(tableName = "dialogue_table")
@Parcelize
data class DialogueDatabase (
@PrimaryKey
val dialogueId: Int,val char1avatar: String,val char2avatar: String,val puzzleDialogueId : Int
): Parcelable
@Entity(tableName = "dialogueLine_table")
@Parcelize
data class DialogueLineDatabase (
@PrimaryKey
val dialogueLineId: Int,val line: String,val speaking: Int,val dialogueForeignkeyId: Int
): Parcelable
这些是关系的类
data class PuzzleWithDialogueDatabase(
@Embedded val puzzle : PuzzleDatabase,@Relation(
entity = DialogueWithLinesDatabase::class,parentColumn = "puzzleId",entityColumn = "puzzleDialogueId"
)
val dialogueWithLines: DialogueWithLinesDatabase
)
data class DialogueWithLinesDatabase(
@Embedded val dialogue:DialogueDatabase,@Relation(
parentColumn = "dialogueId",entityColumn = "dialogueForeignkeyId"
)
val dialogueLines: List<DialogueLineDatabase>
)
这是我的事
@Dao
interface PuzzleDatabaseDao {
@Transaction
@Insert(onConflict = OnConflictStrategy.IGNORE)
fun insertAll(puzzle: List<PuzzleWithDialogueDatabase>)
@Transaction
@Query("SELECT * from puzzle_table ORDER BY puzzleId DESC")
fun getAllPuzzles(): LiveData<List<PuzzleWithDialogueDatabase>>
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)