2017-12-05 3 views
2

java 백엔드 서버에서 uuid를 사용합니다. 그래서 엔티티가 제대로 싱크되었는지 확인하기 위해 안드로이드의 uuid를 사용해야합니다. 나는 Is it possible to apply primary key on the text fields in android databasetext as primarykey in android을 알고 있습니다. 이 무언가를 만들고 싶습니다Android에서 PrimaryKey로 String을 사용할 수 있습니까?

@Entity(tableName = CrewColumns.TABLE_NAME) 
@TypeConverters(BigDecimalConverter::class) 
@JsonIgnoreProperties(ignoreUnknown = true) 
class Crew() { 
    constructor (uuid: String) : this() { 
     this.uuid = uuid; 
    } 

    /** 
    * The unique ID of the item. 
    */ 
    @PrimaryKey 
    @ColumnInfo(name = CrewColumns.UUID) 
    var uuid: String = "" 
    @ColumnInfo(name = CrewColumns.NAME) 
    var name: String = "" 
} 

방 (DAO 등)에 문제가 있습니까? 고맙습니다.

+0

. 시도했을 때 어떤 특별한 문제가 발생 했습니까? – CommonsWare

+0

@CommonsWare 현재 없음. – ThomasEdwin

답변

1

android 주석에서 @NonNull로 해당 필드에 주석을 추가해야합니다.

compile 'com.android.support:support-annotations:26.1.0' 

을하고 다음 코드는 간단하다 : 위해 그 앱의 Gradle을이 줄을 추가 당신은 확실히 기본 키로 문자열을 사용할 수 있습니다

@Entity 
public class User { 
    @PrimaryKey 
    @NonNull 
    private String email; 

    ... 
}