Skip to content

Commit

Permalink
add city hotel entity
Browse files Browse the repository at this point in the history
  • Loading branch information
leelance committed Nov 27, 2016
1 parent 1f5e658 commit e23ea9d
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.lance.querydsl.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="t_city")
public class CityEntity implements Serializable {
private static final long serialVersionUID = -2451005683000059023L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@Column(nullable = false)
private String name;

private String state;

private String country;

private String map;

@OneToMany(mappedBy="city", cascade=CascadeType.ALL, fetch=FetchType.EAGER, orphanRemoval=true)
private Set<HotelEntity>hotels = new HashSet<>();

public CityEntity() {
}

public CityEntity(String name, String country) {
super();
this.name = name;
this.country = country;
}

public String getName() {
return this.name;
}

public String getState() {
return this.state;
}

public String getCountry() {
return this.country;
}

public String getMap() {
return this.map;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public void setName(String name) {
this.name = name;
}

public void setState(String state) {
this.state = state;
}

public void setCountry(String country) {
this.country = country;
}

public void setMap(String map) {
this.map = map;
}

public Set<HotelEntity> getHotels() {
return hotels;
}

public void setHotels(Set<HotelEntity> hotels) {
this.hotels = hotels;
}

@Override
public String toString() {
return getName() + "," + getState() + "," + getCountry();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.lance.querydsl.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name="t_hotel")
public class HotelEntity implements Serializable {
private static final long serialVersionUID = -6355579263029117475L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@ManyToOne(optional = false)
@JoinColumn(name="city_id")
private CityEntity city;

@Column(nullable = false)
private String name;

@Column(nullable = false)
private String address;

protected HotelEntity() {
}

public HotelEntity(CityEntity city, String name) {
this.city = city;
this.name = name;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public CityEntity getCity() {
return city;
}

public void setCity(CityEntity city) {
this.city = city;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}
}

0 comments on commit e23ea9d

Please sign in to comment.