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 MAPPINGAccess Type of an Embeddable ClassThe access type of an embeddable class is determined by the access type of the entity class in which itexists. If the entity explicitly uses a property access type, an embeddable object will implicitly useproperty access as well. A different access type for an embeddable class can be specified by means of the@Access annotation.The Customer entity (see Listing 3-36) and Address entity (see Listing 3-37) use different access types.Listing 3-36. The Customer Entity <strong>with</strong> Field Access Type@Entity@Access(AccessType.FIELD)public class Customer {@Id @GeneratedValueprivate Long id;@Column(name = "first_name", nullable = false, length = 50)private String firstName;@Column(name = "last_name", nullable = false, length = 50)private String lastName;private String email;@Column(name = "phone_number", length = 15)private String phoneNumber;@Embeddedprivate Address address;}// Constructors, getters, settersListing 3-37. The Embeddable Object <strong>with</strong> Property Access Type@Embeddable@Access(AccessType.PROPERTY)public class Address {private String street1;private String street2;private String city;private String state;private String zipcode;private String country;// Constructors@Column(nullable = false)public String getStreet1() {return street1;}89

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

Saved successfully!

Ooh no, something went wrong!