· 9 years ago · Nov 04, 2016, 01:56 PM
1CREATE TABLE IF NOT EXISTS `body_part` (
2 `id` INT NOT NULL AUTO_INCREMENT,
3 `description` VARCHAR(45) NOT NULL,
4 PRIMARY KEY (`id`));
5
6
7CREATE TABLE IF NOT EXISTS `body_part_hit` (
8 `id` INT NOT NULL AUTO_INCREMENT,
9 `id_body_part` INT NOT NULL,
10 `perc_damage_hit` DECIMAL(4,2) NOT NULL,
11 PRIMARY KEY (`id`),
12 INDEX `fk_body_part_hit_1_idx` (`id_body_part` ASC),
13 CONSTRAINT `fk_body_part_hit_1`
14 FOREIGN KEY (`id_body_part`)
15 REFERENCES `body_part` (`id`)
16 ON DELETE NO ACTION
17 ON UPDATE NO ACTION);
18
19
20@MappedSuperclass
21public abstract class BaseEntity<ID> implements Serializable{
22 private static final long serialVersionUID = 1L;
23
24 @Id
25 @GeneratedValue(strategy = GenerationType.IDENTITY)
26 private Integer id;
27
28 // get and set
29}
30
31Entity
32@Table(name = "body_part")
33@XmlRootElement(name = "bodyPart")
34public class BodyPart extends BaseEntity<Integer> {
35 private static final long serialVersionUID = 1L;
36
37 @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
38 @JoinColumn(name = "id", unique = true, nullable = false, updatable = false)
39 private BodyPartHit bodyPartHit;
40
41 private String description;
42 // get and set
43}
44
45@Entity
46@Table(name = "body_part_hit")
47@XmlRootElement(name = "bodyPartHit")
48public class BodyPartHit extends BaseEntity<Integer> {
49 private static final long serialVersionUID = 1L;
50
51 @Column(name = "perc_damage_hit")
52 private BigDecimal percentDamageHit;
53
54 @Column(name = "id_body_part)
55 private Integer idBodyPart;
56
57 // get and set
58}