persistence icon indicating copy to clipboard operation
persistence copied to clipboard

How to create primary key with two fields?

Open fechidal89 opened this issue 10 years ago • 4 comments

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,

fechidal89 avatar Apr 14 '15 16:04 fechidal89

There's no support for composite primary keys. Sorry.

casidiablo avatar Apr 14 '15 16:04 casidiablo

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?

fechidal89 avatar Apr 14 '15 16:04 fechidal89

You can use annotations to mark a field as primary key via @PrimaryKey. And yes, you need a primary key.

casidiablo avatar Apr 14 '15 16:04 casidiablo

What feature has the ExampleNotAutoincrement class so the id is not autoincrement?

at NotAutoincrementInsertionTest.java "ExampleNotAutoincrement foo = new ExampleNotAutoincrement(); foo.id = 1;"

Thanks!

fechidal89 avatar Apr 14 '15 22:04 fechidal89