2

I met an error when encountering Android Room. I use the following 3 classes to illustrate. Class A and B are 2 entity classes in an Android app. Class C is a modified class in the Android framework (more specifically, it is a class in the core Java libraries that I am trying to customize).

@Entity
@Dao
public abstract class A extends C {
    @PrimaryKey
    public int aid;
}
@Entity
@Dao
public abstract class B extends C {
    @PrimaryKey
    public int bid;

    @Embedded
    public A a;
}
public class C {
    private long cid;
    public void setCid(long cid) {this.cid = cid;}
    public long getCid() {return this.cid;}
}

When I build the Android source, the error I got is error: Multiple fields have the same columnName: cid. Field names: cid, a > cid. (I can also reproduce the error if all 3 classes are put inside an Android app)

I knew this error can be fixed by modifying class A or B. But since I am customizing the Android source, I assume class A or B is not allowed to be changed by me.

Is it possible to fix it just by modifying class C?

Richard Hu
  • 811
  • 5
  • 18

1 Answers1

0

Change private long cid; to private transient long cid; seems to be a solution if you don't need serialize class C.

Richard Hu
  • 811
  • 5
  • 18