Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create table USER (
- ID integer identity primary key auto_increment,
- USER_NAME varchar(50) not null,
- unique(USER_NAME));
- create table MEDIA (
- ID integer identity primary key auto_increment,
- TITLE varchar(50) not null,
- unique(TITLE));
- create table USER_MEDIA (
- USER_ID integer not null,
- MEDIA_ID integer not null,
- RATE integer not null check(RATE >=0 || RATE <=10),
- PRIMARY KEY(USER_ID, MEDIA_ID));
- alter table USER_MEDIA add constraint FK_USER foreign key (USER_ID) references USER(ID) on delete cascade;
- alter table USER_MEDIA add constraint FK_MEDIA foreign key (MEDIA_ID) references MEDIA(ID) on delete cascade;
- @Entity
- @Access(AccessType.FIELD)
- public class User {
- @Id
- private Long id;
- @Column(name="user_name")
- private String name;
- }
- @Entity
- @Access(AccessType.FIELD)
- public class Media{
- @Id
- private Long id;
- @Column(name = "title")
- private String name;
- }
- @Entity
- @Table(name = "USER_MEDIA")
- @Access(AccessType.FIELD)
- public class UserMedia {
- User user;
- Media media;
- Integer rating;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement