001: /**
002: * EasyBeans
003: * Copyright (C) 2007 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: Book.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.examples.ear;
025:
026: import javax.persistence.Entity;
027: import javax.persistence.GeneratedValue;
028: import javax.persistence.GenerationType;
029: import javax.persistence.Id;
030: import javax.persistence.JoinColumn;
031: import javax.persistence.ManyToOne;
032: import javax.persistence.NamedQuery;
033:
034: /**
035: * Define a book.
036: * @author Florent Benoit
037: */
038: @Entity
039: @NamedQuery(name="allBooks",query="select o FROM Book o")
040: public class Book {
041:
042: /**
043: * Primary key.
044: */
045: private long id;
046:
047: /**
048: * Author's book.
049: */
050: private Author author;
051:
052: /**
053: * title of the book.
054: */
055: private String title;
056:
057: /**
058: * Default constructor.
059: */
060: public Book() {
061:
062: }
063:
064: /**
065: * Constructor. Build a new Book with the given title and written by the
066: * given author.
067: * @param title the given title
068: * @param author the given author.
069: */
070: public Book(final String title, final Author author) {
071: setTitle(title);
072: setAuthor(author);
073: }
074:
075: /**
076: * @return the Author of this Book.
077: */
078: @ManyToOne
079: @JoinColumn(name="Author_id")
080: public Author getAuthor() {
081: return author;
082: }
083:
084: /**
085: * Sets the author of this book.
086: * @param author the given author.
087: */
088: public void setAuthor(final Author author) {
089: this .author = author;
090: }
091:
092: /**
093: * @return the title of this book.
094: */
095: public String getTitle() {
096: return title;
097: }
098:
099: /**
100: * Set the title of the book.
101: * @param title - the title of the book
102: */
103: public void setTitle(final String title) {
104: this .title = title;
105: }
106:
107: /**
108: * @return an id for this object (incremented automatically)
109: */
110: @Id
111: @GeneratedValue(strategy=GenerationType.AUTO)
112: public long getId() {
113: return this .id;
114: }
115:
116: /**
117: * Sets the id of this author object.
118: * @param id the given id of this author
119: */
120: public void setId(final long id) {
121: this .id = id;
122: }
123:
124: /**
125: * @return String representation of this entity object.
126: */
127: @Override
128: public String toString() {
129: StringBuilder sb = new StringBuilder(this .getClass().getName());
130: sb.append("[id=");
131: sb.append(getId());
132: sb.append(", title=");
133: sb.append(getTitle());
134: sb.append("]");
135: return sb.toString();
136: }
137: }
|