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 MAPPINGFigure 3-2. The Address entity is mapped to three tables.As you probably understand by now, you can have several annotations in the same entity. If youwant to rename the primary table, you can add the @Table annotation as demonstrated in Listing 3-5.Listing 3-5. The Primary Table Is Renamed to T_ADDRESS@Entity@Table(name = "t_address")@<strong>Second</strong>aryTables({@<strong>Second</strong>aryTable(name = "t_city"),@<strong>Second</strong>aryTable(name = "t_country")})public class Address {}// Attributes, constructor, getters, setters■ Note When you use secondary tables, you must consider the issue of performance. Every time you access anentity, the persistence provider accesses several tables and has to join them. On the other hand, secondary tablescan be a good thing when you have expensive attributes such as binary large objects (BLOBs) that you want toisolate in a different table.67

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

Saved successfully!

Ooh no, something went wrong!