package at.fhj.swd14.pse.comment;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import at.fhj.swd14.pse.message.Message;
import at.fhj.swd14.pse.user.User;

@Entity
@Table(name = "comment")
@NamedQueries({
        @NamedQuery(name = "Comment.findByAuthorId", query = "SELECT c FROM Comment c WHERE c.author.id = :authorUserId"),
        @NamedQuery(name = "Comment.findByMessageId", query = "SELECt c FROM Comment c WHERE c.parentMessage.id = :messageId"),
})
public class Comment implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    private Long id;
    @Column
    private String text;

    @ManyToOne
    private User author;

    @Column(name = "parentmessage_id")
    @ManyToOne
    private Message parentMessage;

	@ManyToMany(cascade = CascadeType.PERSIST)
	@JoinTable(
			name = "like_for_comment",
			joinColumns =
				{
						@JoinColumn(name = "comment_id")
				},
			inverseJoinColumns =
				{
						@JoinColumn(name = "user_id")
				}
			)
	private List<User> users;
	
	public Comment() {

    }

    public Comment(Long id) {
        setId(id);
    }

    public Long getId() {
        return id;
    }

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

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public User getAuthor() {
        return author;
    }

    public void setAuthor(User author) {
        this.author = author;
    }

    public Message getParentMessage() {
        return parentMessage;
    }

    public void setParentMessage(Message parentMessage) {
        this.parentMessage = parentMessage;
    }

    public List<User> getUsers() {
        return this.users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    @Override
    public String toString() {
        return "Comment{" +
                "id=" + getId() +
                ", userId='" + getAuthor() + '\'' +
                ", messageId='" + getParentMessage().getId() + '\'' +
                '}';
    }

}

@@ -1059,24 +1059,28 @@
 thor;%0A%0A    @
+Join
 Column(name 
@@ -1101,16 +1101,16 @@
 ge_id%22)%0A
-
     @Man
@@ -1196,17 +1196,20 @@
 ERSIST)%0A
-%09
+    
 @JoinTab
@@ -1211,20 +1211,16 @@
 inTable(
-%0A%09%09%09
 name = %22
@@ -1237,20 +1237,17 @@
 omment%22,
-%0A%09%09%09
+ 
 joinColu
@@ -1247,37 +1247,25 @@
 oinColumns =
-%0A%09%09%09%09%7B%0A%09%09%09%09%09%09
+ 
 @JoinColumn(
@@ -1288,19 +1288,10 @@
 id%22)
-%0A%09%09%09%09%7D,%0A%09%09%09
+, 
 inve
@@ -1310,21 +1310,9 @@
 ns =
-%0A%09%09%09%09%7B%0A%09%09%09%09%09%09
+ 
 @Joi
@@ -1340,18 +1340,8 @@
 id%22)
-%0A%09%09%09%09%7D%0A%09%09%09
 )%0A%09p

fix annotation