Skip to content

Instantly share code, notes, and snippets.

@anncode1
Last active March 9, 2017 16:08
Show Gist options
  • Save anncode1/c567fdb7b7cb2d2b05d923d3207518e7 to your computer and use it in GitHub Desktop.
Save anncode1/c567fdb7b7cb2d2b05d923d3207518e7 to your computer and use it in GitHub Desktop.
package com.ann.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
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.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
@Table(name="social_media")
public class SocialMedia implements Serializable {
private Long idSocialMedia;
private String name;
private String icon;
private List<TeacherSocialMedia> teacherSocialMedias = new ArrayList<TeacherSocialMedia>();
public SocialMedia(String name, String icon) {
this.name = name;
this.icon = icon;
}
public SocialMedia() {
}
public SocialMedia(Long idSocialMedia) {
this.idSocialMedia = idSocialMedia;
}
public SocialMedia(String name) {
this.name = name;
}
@Id
@Column(name="id_social_media")
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Long getIdSocialMedia() {
return idSocialMedia;
}
public void setIdSocialMedia(Long idSocialMedia) {
this.idSocialMedia = idSocialMedia;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name="icon")
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
// @OneToMany//(fetch = FetchType.LAZY, mappedBy ="pk.social")
// @JsonIgnore
// @JoinTable(name="teacher_social_media",joinColumns=@JoinColumn(name="id_social_media"))
@OneToMany
@JoinColumn(name="id_social_media")
@JsonIgnore
public List<TeacherSocialMedia> getTeacherSocialMedias() {
return teacherSocialMedias;
}
public void setTeacherSocialMedias(List<TeacherSocialMedia> teacherSocialMedias) {
this.teacherSocialMedias = teacherSocialMedias;
}
}
package com.ann.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
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.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonManagedReference;
@Entity
@Table(name="teacher")
public class Teacher implements Serializable {
private Long idTeacher;
private String name;
private String avatar;
private List<TeacherSocialMedia> teacherSocialMedias = new ArrayList<TeacherSocialMedia>();
private List<Course> courses;
public Teacher() {
super();
}
public Teacher(Long idTeqcher) {
super();
this.idTeacher = idTeacher;
}
public Teacher(String name, String avatar, List<TeacherSocialMedia> teacherSocialMedias) {
super();
this.name = name;
this.avatar = avatar;
this.teacherSocialMedias = teacherSocialMedias;
}
@Id
@Column(name="id_teacher")
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Long getIdTeacher() {
return idTeacher;
}
public void setIdTeacher(Long idTeacher) {
this.idTeacher = idTeacher;
}
@Column(name="name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name="avatar")
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
// @OneToMany(fetch = FetchType.EAGER)//, mappedBy = "pk.teacher", cascade=CascadeType.ALL)
// @JsonIgnore
// @JoinTable(name="teacher_social_media",joinColumns=@JoinColumn(name="id_teacher"))
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name="id_teacher")
public List<TeacherSocialMedia> getTeacherSocialMedias() {
return teacherSocialMedias;
}
public void setTeacherSocialMedias(List<TeacherSocialMedia> teacherSocialMedias) {
this.teacherSocialMedias = teacherSocialMedias;
}
@OneToMany(mappedBy="teacher")
@JsonIgnore
public List<Course> getCourses() {
return courses;
}
public void setCourses(List<Course> courses) {
this.courses = courses;
}
}
package com.ann.model;
import java.io.Serializable;
import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
@Table(name = "teacher_social_media")
public class TeacherSocialMedia implements Serializable {
@Column(name="nickname")
private String nickname;
@Id
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="id_teacher")
@JsonIgnore
private Teacher teacher;
@Id
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="id_social_media")
private SocialMedia socialMedia;
public TeacherSocialMedia() {
super();
// TODO Auto-generated constructor stub
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
//
//
// public Long getIdTeacher() {
// return idTeacher;
// }
//
//
// public void setIdTeacher(Long idTeacher) {
// this.idTeacher = idTeacher;
// }
//
//
// public Long getIdSocialMedia() {
// return idSocialMedia;
// }
//
//
// public void setIdSocialMedia(Long idSocialMedia) {
// this.idSocialMedia = idSocialMedia;
// }
public Teacher getTeacher() {
return teacher;
}
public void setTeacher(Teacher teacher) {
this.teacher = teacher;
}
public SocialMedia getSocialMedia() {
return socialMedia;
}
public void setSocialMedia(SocialMedia socialMedia) {
this.socialMedia = socialMedia;
}
// @EmbeddedId
// public TeacherSocialMediaId getTeacherSocialMediaId() {
// return teacherSocialMediaId;
// }
// public void setTeacherSocialMediaId(TeacherSocialMediaId teacherSocialMediaId) {
// this.teacherSocialMediaId = teacherSocialMediaId;
// }
// @Transient
// public Teacher getTeacher() {
// return teacherSocialMediaId.getTeacher();
// }
// public void setTeacher(Teacher teacher) {
// teacherSocialMediaId.setTeacher(teacher);
// }
// @Transient
// public SocialMedia getSocialMedia() {
// return teacherSocialMediaId.getSocialMedia();
// }
// public void setSocialMedia(SocialMedia socialMedia) {
// teacherSocialMediaId.setSocialMedia(socialMedia);
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment