realm / realm-kotlin

Kotlin Multiplatform and Android SDK for the Realm Mobile Database: Build Better Apps Faster.
Apache License 2.0
962 stars 61 forks source link

Object isnt part of the schema for this Realm #1841

Open Aramaram174 opened 1 month ago

Aramaram174 commented 1 month ago

How frequently does the bug occur?

Always

Description

import io.realm.RealmObject import io.realm.annotations.PrimaryKey import io.realm.annotations.RealmClass

@RealmClass open class Event ( @PrimaryKey var id: Long = 0, var gameID: Long = 0 ) :RealmObject()

Why this object is not part of the schema for this Realm?

Stacktrace & log output

FATAL EXCEPTION: DefaultDispatcher-worker-2
                                                                                                    Process: com.example.testrealm, PID: 18755
                                                                                                    io.realm.exceptions.RealmException: Event is not part of the schema for this Realm
                                                                                                        at io.realm.internal.modules.CompositeMediator.getMediator(CompositeMediator.java:205)
                                                                                                        at io.realm.internal.modules.CompositeMediator.isEmbedded(CompositeMediator.java:181)
                                                                                                        at io.realm.Realm.createObject(Realm.java:1121)
                                                                                                        at com.example.testrealm.MainActivity$addEvent$1.invokeSuspend$lambda$1$lambda$0(MainActivity.kt:22)
                                                                                                        at com.example.testrealm.MainActivity$addEvent$1.$r8$lambda$jDJOFMmqyyuDFh97NeF17-dThAQ(Unknown Source:0)
                                                                                                        at com.example.testrealm.MainActivity$addEvent$1$$ExternalSyntheticLambda0.execute(D8$$SyntheticClass:0)
                                                                                                        at io.realm.Realm.executeTransaction(Realm.java:1633)
                                                                                                        at com.example.testrealm.MainActivity$addEvent$1.invokeSuspend(MainActivity.kt:21)
                                                                                                        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                                                                                                        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
                                                                                                        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
                                                                                                        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
                                                                                                        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
                                                                                                        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
                                                                                                        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
                                                                                                        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
                                                                                                        Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@cc9bcc0, Dispatchers.IO]

Can you reproduce the bug?

Always

Reproduction Steps

After run project show this bug

Version

10.11.0

What Atlas App Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Android 13

Build environment

Android Studio version: ...Android Studio Iguana | 2023.2.1 Patch 1, 17.0.9 Android Build Tools version: ...34 Gradle version: ...gradle-8.4-bin.zip

sync-by-unito[bot] commented 1 month ago

➤ PM Bot commented:

Jira ticket: RKOTLIN-1130

Aramaram174 commented 1 month ago

https://github.com/Aramaram174/RealmDBTest.git

galacticfungus commented 1 month ago

You don't need @RealmClass, just

class Event() : RealmObject {
  @PrimaryKey
  var id: ObjectId = ObjectId()
  var gameId : Long = 0L
}