Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. create table USER (
  2. ID integer identity primary key auto_increment,
  3. USER_NAME varchar(50) not null,
  4. unique(USER_NAME));
  5.  
  6. create table MEDIA (
  7. ID integer identity primary key auto_increment,
  8. TITLE varchar(50) not null,
  9. unique(TITLE));
  10.  
  11. create table USER_MEDIA (
  12. USER_ID integer not null,
  13. MEDIA_ID integer not null,
  14. RATE integer not null check(RATE >=0 || RATE <=10),
  15. PRIMARY KEY(USER_ID, MEDIA_ID));
  16.  
  17. alter table USER_MEDIA add constraint FK_USER foreign key (USER_ID) references USER(ID) on delete cascade;
  18. alter table USER_MEDIA add constraint FK_MEDIA foreign key (MEDIA_ID) references MEDIA(ID) on delete cascade;
  19.  
  20. @Entity
  21. @Access(AccessType.FIELD)
  22. public class User {
  23. @Id
  24. private Long id;
  25. @Column(name="user_name")
  26. private String name;
  27. }
  28.  
  29. @Entity
  30. @Access(AccessType.FIELD)
  31. public class Media{
  32. @Id
  33. private Long id;
  34. @Column(name = "title")
  35. private String name;
  36. }
  37.  
  38. @Entity
  39. @Table(name = "USER_MEDIA")
  40. @Access(AccessType.FIELD)
  41. public class UserMedia {
  42. User user;
  43. Media media;
  44. Integer rating;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement