Fixed
Status Update
Comments
da...@google.com <da...@google.com> #2
Thanks for reporting this issue and providing a sample project! This is occurring due to a limit in the amount of binding parameters in an SQLite query (its 999), so in Room we have workaround it for one-to-many but look like that same workaround didn't quite translate to one-to-one. We'll be working on a fix for this soon.
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 8331d96ce8ab2b68f391211ffaecb8db32be5a5c
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Wed Oct 30 08:53:48 2019
Handle @Relation annotation with non-list type of more than 999 rows.
When fetching one-to-one relationships where there are more than 999
parent items we need to batch query the children. We already had the
mechanism to do this for one-to-many and many-to-many but for one-to-one
the same strategy failed because the batching code relied in the value
of the relating map to be a collection, a reference that can be passed
around and filled separately. Meanwhile for one-to-one we have to
copy the batch map into the original relationship map.
Bug: 143105450
Test: PojoWithRelationTest, BareRelationDatabaseTest
Change-Id: I00fac5076d4243e973d0e9e2801fef659d518e05
M room/compiler/src/main/kotlin/androidx/room/ext/javapoet_ext.kt
M room/compiler/src/main/kotlin/androidx/room/writer/RelationCollectorMethodWriter.kt
M room/integration-tests/noappcompattestapp/src/androidTest/java/androidx/room/integration/noappcompat/BareRelationDatabaseTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/dao/RobotsDao.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/PojoWithRelationTest.java
A room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/vo/RobotAndHivemind.java
https://android-review.googlesource.com/1154502
https://goto.google.com/android-sha1/8331d96ce8ab2b68f391211ffaecb8db32be5a5c
Branch: androidx-master-dev
commit 8331d96ce8ab2b68f391211ffaecb8db32be5a5c
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Wed Oct 30 08:53:48 2019
Handle @Relation annotation with non-list type of more than 999 rows.
When fetching one-to-one relationships where there are more than 999
parent items we need to batch query the children. We already had the
mechanism to do this for one-to-many and many-to-many but for one-to-one
the same strategy failed because the batching code relied in the value
of the relating map to be a collection, a reference that can be passed
around and filled separately. Meanwhile for one-to-one we have to
copy the batch map into the original relationship map.
Bug: 143105450
Test: PojoWithRelationTest, BareRelationDatabaseTest
Change-Id: I00fac5076d4243e973d0e9e2801fef659d518e05
M room/compiler/src/main/kotlin/androidx/room/ext/javapoet_ext.kt
M room/compiler/src/main/kotlin/androidx/room/writer/RelationCollectorMethodWriter.kt
M room/integration-tests/noappcompattestapp/src/androidTest/java/androidx/room/integration/noappcompat/BareRelationDatabaseTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/dao/RobotsDao.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/PojoWithRelationTest.java
A room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/vo/RobotAndHivemind.java
da...@google.com <da...@google.com> #4
This is fixed internally and will be available in what might be Room 2.2.2
Description
Version used: 2.2.0
Devices/Android versions reproduced on:
- device usb:336662528X product:xcover4ltexx model:SM_G390F device:xcover4lte transport_id:5
- device product:sdk_gphone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:4
- device usb:336662528X product:zerofltexx model:SM_G920F device:zeroflte transport_id:15
In Version 2.1.0 annotation @Relation was only allowed for list types, if you used it on a non-list type the following runtime error occured:
error: Fields annotated with @Relation must be a List or Set.
Since Version 2.2.0 @Relation can be used on non-list types, in order to model relations with a single object reference.
This is handy if you have 1-to-1 relations and you don't have to explicitly get the first item from the result list, instead you get the object directly.
release notes:
One-to-One Relations: The restriction in POJO fields annotated with @Relation to be of type List or Set has been lifted, effectively allowing single-value relations to be represented.
It seems that this new feature is only supported up to a certain amount of table rows. In more details it means that if you run a query on tables with 100 rows, the returned POJOs have all valid non-null references to the object specified by the @Relation annotation. If you run the same query on tables with more than 999 rows (999 still works, 1000 will fail) the result will be that all returned POJOs have NULL as referenced object (see my example project).
If you use the list type with @Relation annotation you don't have this limitation.
Please refer to the attached example project unit test.
In the example project the same entities are used but with two different POJO types. One is using a List<> type annotated with @Relation, and the other is using the newly supported object type.
Android unit test show that the list type always works but the object type works up to 999 rows, after that it starts to fail.