Skip to content

how to set composite primary key? #712

Closed
@wangxuyang518

Description

@wangxuyang518

I have to set composite primary key. how to do it? set tow @id on fileds?

Activity

greenrobot-team

greenrobot-team commented on Jun 26, 2017

@greenrobot-team
Collaborator

Keep the regular @Id Long id. But define a unique index over the properties that you want to use as the actual identifier:

@Entity(      
        // Define indexes spanning multiple columns here.
        indexes = {
                @Index(value = "prop1 DESC, prop2 DESC", unique = true)
        }
)
public class YourEntity {
    @Id(autoincrement = true)
    Long id;
    Integer prop1;
    Long prop2;
  ...
}

-ut

greenrobot-team

greenrobot-team commented on Jul 18, 2017

@greenrobot-team
Collaborator

Thumbs up, so closing. -ut

removed their assignment
on Jul 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @wangxuyang518@greenrobot-team

        Issue actions

          how to set composite primary key? · Issue #712 · greenrobot/greenDAO