A RealmObject with no @PrimaryKey cannot be updated
A developer of VCNC encountered the following error message. He uses Realm version 0.84.1 and thinks that RAnniversaryView already has a primary key field.
Non-fatal Exception: java.lang.IllegalArgumentException: A RealmObject with no @PrimaryKey cannot be updated: class kr.co.vcnc.android.couple.model.viewmodel.RAnniversaryView
at io.realm.Realm.checkHasPrimaryKey(Realm.java:1144)
at io.realm.Realm.copyToRealmOrUpdate(Realm.java:765)
at io.realm.Realm.copyToRealmOrUpdate(Realm.java:811)
at kr.co.vcnc.android.couple.feature.home.HomeController$2.lambda$call$813(HomeController.java:214)
at kr.co.vcnc.android.couple.feature.home.HomeController$2.lambda$null$812(HomeController.java)
at kr.co.vcnc.android.couple.feature.home.HomeController$2$$Lambda$2.run(Unknown Source)
at kr.co.vcnc.android.couple.realm.RealmRunnable.lambda$transaction$996(RealmRunnable.java:35)
at kr.co.vcnc.android.couple.realm.RealmRunnable.transaction(RealmRunnable.java)
at kr.co.vcnc.android.couple.realm.RealmRunnable$$Lambda$2.run(Unknown Source)
at kr.co.vcnc.android.couple.realm.RealmRunnable.transaction(RealmRunnable.java:45)
at kr.co.vcnc.android.couple.realm.RealmRunnable.transaction(RealmRunnable.java:34)
at kr.co.vcnc.android.couple.feature.home.HomeController$2.call(HomeController.java:205)
at kr.co.vcnc.android.couple.feature.home.HomeController$2.call(HomeController.java:124)
at kr.co.vcnc.android.couple.rx.ObservableZygote$1.call(ObservableZygote.java:49)
at kr.co.vcnc.android.couple.rx.ObservableZygote$1.call(ObservableZygote.java:45)
at rx.Observable$1.call(Observable.java:144)
at rx.Observable$1.call(Observable.java:136)
at rx.Observable$1.call(Observable.java:144)
at rx.Observable$1.call(Observable.java:136)
at rx.Observable$1.call(Observable.java:144)
at rx.Observable$1.call(Observable.java:136)
at rx.Observable.unsafeSubscribe(Observable.java:7466)
at rx.internal.operators.OperatorSubscribeOn$1$1.call(OperatorSubscribeOn.java:62)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:47)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
@dalinaum Was the realm file created Realm 0.84.1 or older? If so, I suspect that the cause is #1775
@zaki50 If they don't update their version to Realm 0.84.2 or avobe yet, isn't it related to that issue?
This issue should not related with #1775. Since that one only happens when you open the Realm Instance.
This issues is more like trying to update a RealmObject without PK declared.
How does RAnniversaryView look like?
Hi, all, I'm Kevin from VCNC, who reported that issue to @dalinaum.
RAnniversaryView is look like this.
public class RAnniversaryView extends RealmObject {
private RAnniversary model;
@PrimaryKey
private String key;
private Integer order;
public RAnniversaryView() {
}
public RAnniversaryView(CAnniversaryView model) {
if (model.getModel() != null) {
setModel(new RAnniversary(model.getModel()));
}
setKey(model.getKey());
setOrder(model.getOrder());
}
public void setModel(RAnniversary model) {
this.model = model;
}
public RAnniversary getModel() {
return model;
}
@zaki50 and I guess realm file is not created on older version of realm.
I'm putting little more information from crash analytics system. Hope it helps.
@beeender you are right. #1775 is not related this issue.
Attach devices.
- SHV E330S: Samsung Galaxy S4 LTE-A for SKT (SK Telecome, Korea)
- SM G906K: Samsung Galaxy S5 LTE-A for KT (Korea Telecome, Korea)
- SM G906S: Samsung Galaxy S5 LTE-A for SKT
- LG F400S: LG G3 LTE-A for SKT
- LG F460S: LG G3 Cat6 for SKT
- LG F350S: LG G Pro 2 for SKT
- IM A900L: Pantech VEGA Secret UP fot LG U+
- IM A890L: Pantech VEGA Secret Note for LG U+
@swkimme Sorry for the late reply. I was wondering if you can share a code snippet so we can see how you call copyToRealmOrUpdate(). Can you get hold of a copy of a Realm file so we can investigate it?
@kneth Here it is.
if (homeCardsView.getAnniversariesWithOrders() != null) {
RealmRunnable.transaction(realm -> {
CAnniversariesWithOrders anniversariesWithOrders = homeCardsView.getAnniversariesWithOrders();
CCollection<CAnniversary> anniversaries = anniversariesWithOrders.getAnniversaries();
final List<String> orders = homeCardsView.getAnniversariesWithOrders().getOrders();
fj.data.List<RAnniversaryView> rAnniversaryViews = iterableList(anniversaries.getData())
.map(item -> new CAnniversaryView(item, orders.indexOf(item.getId())))
.map(RAnniversaryView::new);
realm.clear(RAnniversaryView.class);
realm.copyToRealmOrUpdate(rAnniversaryViews);
});
}
@kneth For realm files, I can't upload zip file here, I've sent it to @dalinaum. I'll sent it to you, too.
@kneth I've sent it to you again for just in case @swkimme @dalinaum
@swkimme I haven't been reproduce the issue yet :-(
@swkimme I'm not sure if it will help you but we are getting closer to RxJava support - see #1710.
@swkimme Did you have a chance to add some logging of rAnniversaryViews so we can see why the primary key is missing?
Closing due to no response.
Encounter the same issue on devices 4.1.1 and 4.2.2 where it throws no PrimaryKey exception when there is. Using Realm 8.0.0. However, it works on higher version of Android.
@david201601 Can this be reproduced in your side? Or you just got the crash report from fabric?
@beeender I am sorry that I could not reproduce the error after my teams update the realm to the latest version.
I am getting same issue .can someone pls repond me java.lang.IllegalArgumentException: A RealmObject with no @PrimaryKey cannot be updated: http://jsoneditoronline.org/?id=cc5a403d1bbd933c250069a9221fcc02
@engr-erum if you do not have a @PrimaryKey then you should have createAllFromJson https://realm.io/docs/java/latest/api/io/realm/Realm.html#createAllFromJson-java.lang.Class-java.io.InputStream-