0

There are many questions about voting systems so I will cut right to the chase.

My question is about relationships ,

import play.db.jpa.GenericModel;

public class VotesModel extends GenericModel {
    @ManyToOne
    public StatusModel status;
    @ManyToOne
    public UserModel user;
    public Date time;
}

The usual voting rules apply,

  1. A status can have many votes
  2. A user can vote on many status.
  3. But a user can vote only once on a status .

I have easily applied the first 2 rules as @ManyToOne , How do I apply the 3rd and most important rule?

Environment:

Playframework 1.2.5 , MySQL

Gautam
  • 7,868
  • 12
  • 64
  • 105

1 Answers1

1

Make a composite key out of status and user

SJuan76
  • 24,532
  • 6
  • 47
  • 87
  • I found the answer with your help, but please update the answer with some code on creating a compound/composite key so that I can accept your answer . – Gautam Aug 16 '12 at 05:34
  • http://www.google.es/search?q=jpa+composite+id&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:es-ES:official&client=firefox-a&safe=strict – SJuan76 Aug 16 '12 at 07:25
  • I found that and solved the issue , Can you please add the details to your answer so that its complete and I can accept it . – Gautam Aug 16 '12 at 07:32
  • 1
    Why should there be code in the answer? There are a lot of examples one can find using Google or the search engine on stackoverflow. The web doesn't need another one. For you the answer worked so why not accept it? – siebz0r Aug 16 '12 at 10:49