Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to set composite primary key? #712

Closed
wangxuyang518 opened this issue Jun 26, 2017 · 2 comments
Closed

how to set composite primary key? #712

wangxuyang518 opened this issue Jun 26, 2017 · 2 comments

Comments

@wangxuyang518
Copy link

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

@greenrobot-team
Copy link
Collaborator

greenrobot-team commented Jun 26, 2017

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
Copy link
Collaborator

Thumbs up, so closing. -ut

@greenrobot-team greenrobot-team removed their assignment Jul 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants