Skip to content

Instantly share code, notes, and snippets.

@AndySun25
Created April 5, 2016 09:59
Show Gist options
  • Save AndySun25/a745b4fb90df4c0480420bc718b8688e to your computer and use it in GitHub Desktop.
Save AndySun25/a745b4fb90df4c0480420bc718b8688e to your computer and use it in GitHub Desktop.
package models;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Collection;
@Entity
@Table(name = "post")
public class Post {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;
@OneToOne
@JoinColumn(name = "user_id")
private User user;
@Column(name = "title")
private String title;
@Column(name = "content")
private String content;
@Column(name = "created_at", insertable=false, updatable = false)
private Timestamp created_at;
@Column(name = "view_count")
private int view_count;
@ManyToMany(targetEntity = Tag.class)
@JoinTable(
name = "post_has_tags",
joinColumns=@JoinColumn(name = "post_id"),
inverseJoinColumns=@JoinColumn(name = "tag_id")
)
private Collection tags;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment