gpt4 book ai didi

android - Room 2.5一对一多对一嵌套关系

转载 作者:行者123 更新时间:2023-12-02 13:26:55 28 4
gpt4 key购买 nike

房间
我有这样的关系
拼图->有一个->对话->有很多->对话行
我遵循了
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:错误:找不到以下 setter Realm 。
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 prompt: String,
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>>
}

最佳答案

@Relation中的实体属性应提及数据库实体,而不是关系类。尝试:

data class PuzzleWithDialogueDatabase(
@Embedded val puzzle : PuzzleDatabase,
@Relation(
entity = DialogueDatabase::class,
parentColumn = "puzzleId",
entityColumn = "puzzleDialogueId"
)
val dialogueWithLines: DialogueWithLinesDatabase
)

关于android - Room 2.5一对一多对一嵌套关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63394629/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com