12.07.2015 Views

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 3 ■ OBJECT-RELATIONAL MAPPING@Table annotation). The @Id annotation defines the primary key as being autogenerated, and a @Columnannotation sets the size of the description to 500 characters long.Listing 3-29. The Book Entity <strong>with</strong> Only a Few Annotations@Entitypublic class Book {@Id@GeneratedValue(strategy = GenerationType.AUTO)private Long id;private String title;private Float price;@Column(length = 500)private String description;private String isbn;private Integer nbOfPage;private Boolean illustrations;// Constructors, getters, setters}In a separate book_mapping.xml file (see Listing 3-30), following a specified XML schema, you canchange the mapping for any data of the entity. The tag allows you to change the name of thetable to which the entity will be mapped (BOOK_XML_MAPPING instead of the default BOOK). Inside the tag, you can customize the attributes, specifying not only their name and length, but alsotheir relationships <strong>with</strong> other entities. For example, you can change the mapping for the title columnand the number of pages (nbOfPage).Listing 3-30. Mapping the File META-INF/book_mapping.xml85

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!