118 CHAPTER 6 n MAPPING WITH ANNOTATIONS CHAPTER (Web hosting comparison)
Wednesday, April 25th, 2007118 CHAPTER 6 n MAPPING WITH ANNOTATIONS CHAPTER 6 n MAPPING WITH ANNOTATIONS Listing 6-16. Mapping a Many-to-One Relationship from the PublisherEntity to the Book Entity @ManyToOne @JoinColumn(name = “publisher_id”) public Publisher getPublisher() { return publisher; } The @ManyToOne annotation takes a similar set of attributes to @OneToMany. The following list describes the attributes, all of which are optional. cascade indicates the appropriate cascade policy for operations on the association; it defaults to none. fetch indicates the fetch strategy to use; it defaults to LAZY. optional indicates whether the value can be null; it defaults to true. targetEntity indicates the entity that stores the primary key this is normally inferred from the type of the field or property (Publisherin the preceding example). We have also supplied the optional @JoinColumnattribute to name the foreign key column required by the association something other than the default (publisher) this is not necessary, but it illustrates the use of the annotation. When a unidirectional one-to-many association is to be formed, it is possible to express the relationship using a link table. This is achieved by adding the @JoinTable annotation as shown in Listing 6-17.2 Listing 6-17. A Simple Unidirectional One-to-Many Association with a Join Table @OneToMany(cascade = ALL) @JoinTable public Set
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision mysql hosting services