Status Update
Comments
ad...@google.com <ad...@google.com>
da...@google.com <da...@google.com> #2
This is indeed a long standing issue in Room and will likely be more relevant with the map / multimap return type. I think we can show a warning to start but we'll also take a deeper look to see how we can solve the duplicate column name issue.
As a workaround you can always use a column alias and a POJO class with matching field name.
jl...@gmail.com <jl...@gmail.com> #3
Branch: androidx-main
commit 894b0ff2c1b095a46803975f400a561eb974ea28
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Fri Oct 29 10:56:31 2021
Duplicate column resolution heuristic algorithm
AmbiguousColumnResolver contains an algorithm to map query result columns to data objects (POJOs) columns. We call data object columns 'mapping' and in a multimap query where there might be multiple data objects we refer to the list of all their columns 'mappings'. The algorithm uses a grouping / neighboring strategy to assign the duplicate columns to their right data objects matching their name along with taking into account the the nearby columns since in a star-projected query all columns coming from a table will appear in the result before the next table. Room will generate code that uses the algorithm at runtime if the query has a star-projection, if not then Room will use the algorithm during compile-time since the columns result order is known and fixed.
The algorithm does not solve all cases, specifically those where one of the data objects has a single column which is the duplicate column. For those situation Room will warn the user so that they alias the duplicate column. For other odd cases, Room will behave as it used to, picking the first result column that matches with the data object column.
Bug: 201306012
Bug: 212279118
Test: AmbiguousColumnResolverTest
Relnote: Room will now attempt to resolve ambiguous columns in a multimap query. This allows for JOINs with tables containing same-name tables to be correctly mapped to a result data object.
Change-Id: I4b444b042245a334cc3f362f3239721ce0b6bd1e
M room/room-compiler/src/main/kotlin/androidx/room/solver/query/result/EntityRowAdapter.kt
M room/room-compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
A room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/AmbiguousColumnResolverTest.kt
M room/room-compiler/src/main/kotlin/androidx/room/solver/query/result/PojoRowAdapter.kt
M room/room-common/api/current.txt
M room/room-compiler/src/main/kotlin/androidx/room/vo/Warning.kt
M room/room-runtime/api/restricted_current.txt
A room/room-common/src/main/java/androidx/room/AmbiguousColumnResolver.kt
M room/room-common/api/public_plus_experimental_current.txt
M room/room-common/build.gradle
M room/room-compiler/src/main/kotlin/androidx/room/processor/ProcessorErrors.kt
M room/room-common/src/main/java/androidx/room/RoomWarnings.kt
M room/room-compiler/src/main/kotlin/androidx/room/solver/query/result/MultimapQueryResultAdapter.kt
M room/room-compiler/src/main/kotlin/androidx/room/solver/query/result/GuavaImmutableMultimapQueryResultAdapter.kt
M room/room-runtime/src/main/java/androidx/room/util/CursorUtil.kt
M room/room-compiler/src/main/kotlin/androidx/room/ext/javapoet_ext.kt
A room/room-compiler/src/main/kotlin/androidx/room/solver/query/result/AmbiguousColumnIndexAdapter.kt
M room/room-compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
M room/room-compiler/src/main/kotlin/androidx/room/solver/query/result/ImmutableMapQueryResultAdapter.kt
A room/room-common/src/test/java/androidx/room/AmbiguousColumnResolverTest.kt
M room/room-compiler/src/main/kotlin/androidx/room/solver/query/result/MapQueryResultAdapter.kt
M room/room-common/api/restricted_current.txt
da...@google.com <da...@google.com> #4
@Entity
data class RoomSubTrip(
@PrimaryKey val id: String,
val startDate: Long,
val endDate: Long?,
val estimatedActivity: UserActivity,
val tripId: String,
)
@Entity
data class RoomSubTripSensorData(
@PrimaryKey(autoGenerate = true)
val id: Int = 0,
val tripId: String,
val subTripId: String,
val recording: String
)
@Transaction
@Query(
"SELECT * FROM RoomSubTrip JOIN RoomSubTripSensorData " +
"ON RoomSubTrip.id = RoomSubTripSensorData.subTripId "
)
fun getSubTripWithSensorRecordings(): Map<RoomSubTrip, List<RoomSubTripSensorData>>
This return map with RoomSubTrip with id from RoomSubTripSensorData.id
jl...@gmail.com <jl...@gmail.com> #5
Sorry, the fix for this issue is in Room 2.5.0 and not 2.4.x, we are working on getting a stable release of 2.5.0 soon.
ap...@google.com <ap...@google.com> #6
Need to know if I should wait for the update or refactor my code.
da...@google.com <da...@google.com>
an...@google.com <an...@google.com> #7
Room 2.5.0-rc01 was recently released, the next release will be 2.5.0. Unfortunately the US holidays are around the corner and the next androidx release will be early next year.
be...@bytedance.com <be...@bytedance.com> #8
Room 2.5.1, this issue still exists when selecting using a join to filter data but omitting the joined data in the result. E.g. when Entity1
has column named id
and Entity2
also has id
, and I use a @Query
that returns a List<Entity1>
with a simple join in order to filter only those of Entity1
who have a relation to certain Entity2
. The resulting List<Entity1>
contains instances of Entity1
whose ids are wrongly assigned to those of their respective joined Entity2
. And that is regardless whether @RewriteQueriesToDropUnusedColumns
is being used or not.
Description
I get the error that the @Generated Annotation can not be found because the package javax.annotation does not exist.
CustomerDao_Impl.java:24: error: package javax.annotation does not exist
import javax.annotation.Generated;
CustomerDao_Impl.java:26: error: cannot find symbol
@Generated("androidx.room.RoomProcessor")
This happens when compiling an Android App on Mac OS with
javac --version
javac 10.0.2
I use version 2.1.0 for room-runtime and room-compiler
In Android Studio the app builds fine.
I found a similar issue in Dagger: