Fixed
Status Update
Comments
da...@google.com <da...@google.com> #2
Thanks for filling this, definitely a bug in Room, We'll try to fix it for an upcoming alpha.
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-master-dev
commit ec04a408c288fd01f7e2a42d9aedad98e94289d9
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Wed Jul 31 14:50:04 2019
Conditionally error due to missing getter/setter based on binding scope.
When processing a POJO with binding scope to bind to query only, then
it is OK if the POJO has no setter or constructor. Likewise if a POJO
with binding scope to read from cursor, then it is OK to have no
getter. When the binding scope is two-way, then both getters and
setters are needed (or getter and matching constructor).
Bug: 138664463
Test: PojoProcessorTest
Change-Id: I1324f2e55174aa9999498666000b86591d05e970
M room/compiler/src/main/kotlin/androidx/room/processor/PojoProcessor.kt
M room/compiler/src/test/kotlin/androidx/room/processor/PojoProcessorTest.kt
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/BooksDao.kt
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/vo/Book.kt
A room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/vo/MiniBook.kt
https://android-review.googlesource.com/1094751
https://goto.google.com/android-sha1/ec04a408c288fd01f7e2a42d9aedad98e94289d9
Branch: androidx-master-dev
commit ec04a408c288fd01f7e2a42d9aedad98e94289d9
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Wed Jul 31 14:50:04 2019
Conditionally error due to missing getter/setter based on binding scope.
When processing a POJO with binding scope to bind to query only, then
it is OK if the POJO has no setter or constructor. Likewise if a POJO
with binding scope to read from cursor, then it is OK to have no
getter. When the binding scope is two-way, then both getters and
setters are needed (or getter and matching constructor).
Bug: 138664463
Test: PojoProcessorTest
Change-Id: I1324f2e55174aa9999498666000b86591d05e970
M room/compiler/src/main/kotlin/androidx/room/processor/PojoProcessor.kt
M room/compiler/src/test/kotlin/androidx/room/processor/PojoProcessorTest.kt
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/BooksDao.kt
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/vo/Book.kt
A room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/vo/MiniBook.kt
Description
Version used: 2.2.0-alpha01
Devices/Android versions reproduced on: Pixel 3 XL / Android P
I've tried to use the new awesome Target Entity feature that introduced at 2.2.0-alpha01.
But, I encountered the Room compiler error.
It seems to happen if try inserting immutable data class using @Insert(entity = ImmutableDataClass::class)
The error message says "Cannot find setter for field.". But, the generated Dao_Impl code does not use the setter methods.
Is this a Room compiler bug?
The workaround is replacing val to var.
Here is sample codes:
```
@Database(entities = [Project::class], version = 1)
abstract class TargetEntityDatabase : RoomDatabase() {
abstract fun projectDao(): ProjectDao
}
@Entity
data class Project(
@PrimaryKey
val id: Long,
val title: String,
@ColumnInfo(defaultValue = "''")
val longDescription: String
)
data class ProjectMiniApiEntity(
val id: Long,
val title: String
)
@Dao
interface ProjectDao {
@Insert(entity = Project::class)
fun insertNewProject(projectMini: ProjectMiniApiEntity)
}
```
Gradle logs:
```
> Task :app:kaptDebugKotlin FAILED
e: ProjectMiniApiEntity.java:20: error: Cannot find setter for field.
private final long id = 0L;
^
e: ProjectMiniApiEntity.java:22: error: Cannot find setter for field.
private final java.lang.String title = null;
^
```