Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE unit
- (
- id BIGINT PRIMARY KEY AUTO_INCREMENT,
- code VARCHAR(20) UNIQUE NOT NULL,
- description VARCHAR(100) NOT NULL
- );
- CREATE TABLE building
- (
- id BIGINT PRIMARY KEY AUTO_INCREMENT,
- code VARCHAR(20) UNIQUE NOT NULL,
- name VARCHAR(100) NOT NULL,
- latitude NUMERIC(8,6),
- longitude NUMERIC(8,6)
- );
- CREATE TABLE link_unit_building
- (
- id BIGINT PRIMARY KEY AUTO_INCREMENT,
- unit_id BIGINT NOT NULL,
- building_id BIGINT NOT NULL
- );
- ALTER TABLE link_unit_building ADD(
- CONSTRAINT building_fk
- FOREIGN KEY (building_id)
- REFERENCES building(id)
- ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT unit_fk
- FOREIGN KEY (unit_id)
- REFERENCES unit (id)
- ON DELETE CASCADE ON UPDATE CASCADE);
- ----------------------------------------------------------------------------------------------------------------------------------
- package zesp03.entity;
- import javax.persistence.*;
- /**
- * Created by Berent on 2017-02-20.
- */
- @Entity
- @Table(name = "unit")
- public class Unit {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private Long id;
- @Column(length = 20, unique = true, nullable = false)
- private String code;
- @Column(length = 100, nullable = false)
- private String description;
- }
- ----------------------------------------------------------------------------------------------------------------------------------
- package zesp03.entity;
- import javax.persistence.*;
- /**
- * Created by Berent on 2017-02-20.
- */
- @Entity
- @Table(name = "building")
- public class Building {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private Long id;
- @Column(length = 20, unique = true, nullable = false)
- private String code;
- @Column(length = 100, nullable = false)
- private String name;
- @Column(precision=8, scale=6)
- private Number latitude;
- @Column(precision=8, scale=6)
- private Number longitude;
- }
- ---------------------------------------------------------------------------------------------------------------------------
- package zesp03.entity;
- import javax.persistence.*;
- /**
- * Created by Berent on 2017-02-20.
- */
- @Entity
- @Table(name = "link_unit_building")
- public class Link_unit_building {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private Long id;
- @Column(nullable = false)
- private Long unit_id;
- @Column(nullable = false)
- private Long building_id;
- @OneToOne(fetch = FetchType.LAZY)
- @JoinColumn(
- name = "building_id",
- foreignKey = @ForeignKey(name = "building_fk"),
- nullable = false,
- unique = true
- )
- private Building building;
- @OneToOne(fetch = FetchType.LAZY)
- @JoinColumn(
- name = "unit_id",
- foreignKey = @ForeignKey(name = "unit_fk"),
- nullable = false,
- unique = true
- )
- private Unit unit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement