Is it possible to use both Room persistence library's @Entity
with AutoValue's @AutoValue
and builder on the same POJO? How should i do it?

- 1,027
- 8
- 22
-
3I ran into problems with this and [filed this feature request](https://issuetracker.google.com/issues/62408420), so AFAIK as of `1.0.0-alpha3` this is still not possible. – CommonsWare Jul 02 '17 at 10:46
-
@CommonsWare thanks. if you post it as answer, i will accept it. – Weizhi Jul 02 '17 at 12:35
-
Added comment in the feature request, @CommonsWare did you get any news about it other than the comments in the feature request ? – JoseF Oct 16 '17 at 17:06
-
@JoseF: No, sorry. – CommonsWare Oct 16 '17 at 17:20
-
I see that it was upgraded from Priorty 3 to Priority 2 on Nov. 28, 2017 – Bryon Nicoson Apr 06 '18 at 19:59
5 Answers
AFAIK, as of 1.0.0-alpha3
, this is not possible. Room wants fields; AutoValue doesn't expose fields. Keep tabs on this feature request for progress in this area.

- 986,068
- 189
- 2,389
- 2,491
This feature will be available in Room 2.1.0 https://issuetracker.google.com/issues/62408420#comment27

- 5,388
- 3
- 14
- 29
Released in 2.1.0-alpha01!
Note that you have to add the @CopyAnnotations annotation for it to work
Auto Value: Room now supports declaring AutoValue annotated classes as entities and POJOs. The Room annotations @PrimaryKey, @ColumnInfo, @Embedded and @Relation can now be declared in an auto value annotated class’ abstract methods. Note that these annotation must also be accompanied by @CopyAnnotations for Room to properly understand them.

- 302
- 3
- 12
Following this task, apparently they added support. I assume it will be possible in the future Room release (probably androidx.room version 2.0.0). Still not merged as part of 2.0.0-beta1 though

- 1,681
- 3
- 22
- 33
Now it is possible with the Room database 2.1.0.
You can make this possible by annotating the abstract class methods with @PrimaryKey, @ColumnInfo, @Embedded, and @Relation. The abstract class has to be annotated with @Autovalue.

- 1
- 2