persistence
persistence copied to clipboard
How to create primary key with two fields?
I have this model: private long userId; private long recipeId; private int Score; private int Favorites; private int Followers;
I want that userId and recipeId be my primary key for insert or replace an object.
can I use a composite primary key? -> http://www.objectdb.com/java/jpa/entity/id#Composite_Primary_Key_
Thanks,
There's no support for composite primary keys. Sorry.
I asked because it gave me this error: E/AndroidRuntime(26037): Caused by: java.lang.IllegalStateException: Class class com......Info does not have a primary key
Do I have to put mandatory long id?
You can use annotations to mark a field as primary key via @PrimaryKey. And yes, you need a primary key.
What feature has the ExampleNotAutoincrement class so the id is not autoincrement?
at NotAutoincrementInsertionTest.java "ExampleNotAutoincrement foo = new ExampleNotAutoincrement(); foo.id = 1;"
Thanks!