package com.ibtp.kontor.comics.entity;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;

/**
 * Created by thomas on 17.01.15.
 */
@NamedQueries({
        @NamedQuery(name="Publisher.findAll", query="SELECT p from PublisherEntity as p"),
        @NamedQuery(name="Publisher.findByName", query="SELECT p from PublisherEntity as p WHERE p.name = :name")
})

@Entity
@Table(name = "PUBLISHER")
public class PublisherEntity {

    private Long id;

    private String name;

    private Collection<ComicEntity> comic = new ArrayList<ComicEntity>();

    public PublisherEntity() {}

    public PublisherEntity(String name) {
        setName(name);
    }

    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    public Long getId() { return id; }

    @SuppressWarnings("unused")
    private void setId(Long id) { this.id = id; }

    @Column
    public String getName() { return name; }

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

    public void setComic(Collection<ComicEntity> comic) { this.comic = comic; }

    @OneToMany(mappedBy="publisher", cascade=CascadeType.REMOVE)
    public Collection<ComicEntity> getComic() { return comic; }
}
