Java tutorial
/* The MIT License (MIT) Copyright (c) 2015 QAXML Pty Ltd Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package com.qatickets.domain; import java.io.Serializable; import java.util.Date; 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.ManyToOne; import javax.persistence.Table; import javax.validation.constraints.NotNull; import org.apache.commons.io.FileUtils; import org.hibernate.validator.constraints.Length; import org.hibernate.validator.constraints.NotBlank; @SuppressWarnings("serial") @Entity @Table(name = "TICKET_FILE_ATTACHMENT") public class TicketFileAttachment implements Serializable { @Id @Column(name = "TICKET_VOTE_ID") @GeneratedValue(strategy = GenerationType.AUTO) private int id; @NotNull @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "TICKET_ID") private Ticket ticket; @NotBlank @Length(max = 200) @Column(name = "FILE_NAME") private String fileName; @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "USER_ID") private UserProfile user; @Column(name = "DATE", columnDefinition = "TIMESTAMP") private Date date; @Column(name = "SIZE") private long size; @Length(max = 64) @Column(name = "CONTENT_TYPE") private String contentType; @Column(name = "IMAGE") private boolean image; public String getContentType() { return contentType; } public void setContentType(String contentType) { this.contentType = contentType; } public long getSize() { return size; } public String getSizeReadable() { return FileUtils.byteCountToDisplaySize(size); } public void setSize(long size) { this.size = size; } public boolean isImage() { return image; } public void setImage(boolean image) { this.image = image; } public Ticket getTicket() { return ticket; } public void setTicket(Ticket ticket) { this.ticket = ticket; } public String getFileName() { return fileName; } public void setFileName(String fileName) { this.fileName = fileName; } public UserProfile getUser() { return user; } public void setUser(UserProfile user) { this.user = user; } public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } public int getId() { return id; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + id; return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; TicketFileAttachment other = (TicketFileAttachment) obj; if (id != other.id) return false; return true; } @Override public String toString() { return "TicketFileAttachment [id=" + id + ", fileName=" + fileName + ", user=" + user + ", date=" + date + ", size=" + size + ", contentType=" + contentType + ", image=" + image + "]"; } }