question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

There is a issue if use both realm-java and realm-js

See original GitHub issue

In my android app, I use both realm-java and realm-js. After I created a object in reaml-java, then I query it in react-native with realm-js, but I get null.

This is my code:

// create a Baby object
Realm realm = Realm.getDefaultInstance();

Baby baby = new Baby();
baby.name = "Baby Name";

realm.beginTransaction();
realm.copyToRealm(baby);
realm.commitTransaction();
// then query in react-native
let baby = realm.objects('Baby').filtered('name = "Baby Name"')[0];
// but the result of baby is undefined

It won’t get the result until I reload react-native JS. But I debug in chrome with stetho_realm, I can see the object has been created.

I don’t know whether it’s a bug, or maybe there is a error in my code. But that’s OK in my ios app with using both realm-swift and realm-js.

My environment are:

Mac OS 10.11 Android 5.1 node 5.3 realm-js 0.11.1 java version “1.8.0_66” io.realm:realm-gradle-plugin:0.88.2

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
afranchukcommented, Jan 14, 2018

FWIW, I found the following workaround to be effective:

  1. Add a java-side event that’s fired into the javascript side when the realm changes (via io.realm.Realm.addChangeListener or io.realm.DynamicRealm.addChangeListener).
  2. Debounce change events on the javascript side and do an empty write() on the realm for it to update.
2reactions
chrisdukeycommented, Sep 22, 2017

I’m still getting this issue. I created a new React Native project and installed realm via npm (it installed version 1.12.0 of the realm npm module). On the Android side of things I’m using version 3.7.2 via the realm gradle plugin. I can add an object on the Android side of things but I only see an updated object count in RN if I use @wusuopu’s method of executing an empty write. The problem with that is that the count is alway one behind the actual count. I see this appears to be fixed so am wondering is there something I’m missing in order for my change listener to see changes made via Java?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Will Realm-Java Support Realm-Core 12.11.0 in the near ...
Hello, The team that I work in is moving toward supporting react-native 0.70.0 in order to adopt the many benefits of the new...
Read more >
Using shared Realm db between Android native code and ...
Both of them says its not possible unless you build both Realm Java and RealmJS from scratch. To check this, I created one...
Read more >
Realistic Realm - lessons learned after using it for 1.5 years
Any realm object must both be inherited from RealmObject or implement the RealmModel marker interface and be marked with an @RealmClass ...
Read more >
10.8.0 - realm - npm
There are 102 other projects in the npm registry using realm. ... versions of Realm. Currently we support React Native (both iOS &...
Read more >
Realm JS: A Mobile Database That Runs Directly inside Phones
This project hosts the JavaScript versions of Realm. Currently we support React Native (both iOS & Android), Node.js and Electron (on Windows, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found