122 CHAPTER 6 n MAPPING WITH ANNOTATIONS CHAPTER (Web file server)
122 CHAPTER 6 n MAPPING WITH ANNOTATIONS CHAPTER 6 n MAPPING WITH ANNOTATIONS Listing 6-24. The Root of the Inheritance Hierarchy Mapped with the JOINED Strategy @Entity @Inheritance(strategy = JOINED) @DiscriminatorColumn( name=”DISCRIMINATOR” ) public class Book { … } Finally, there is the table-per-class approach, in which all of the fields of each type in the inheritance hierarchy are stored in distinct tables. Because of the close correspondence between the entity and its table, the @DiscriminatorColumn annotation is not applicable to this inheritance strategy. Listing 6-25 shows how our Book class could be mapped in this way. Listing 6-25. The Root of the Inheritance Hierarchy Mapped with the TABLE_PER_CLASSStrategy @Entity @Inheritance(strategy = TABLE_PER_CLASS) public class Book { … } Other EJB 3 Persistence Annotations Although we have now covered most of the core EJB 3 persistence annotations, there are a few others that you will encounter fairly frequently. We cover some of these in passing in the following sections. Temporal Data Fields or properties of an entity that have java.util.Date or java.util.Calendar types represent temporal data. By default, these will be stored in a column with the TIMESTAMP data type, but this default behavior can be overridden with the @Temporalannotation. The annotation accepts a single value attribute from the javax.persistence. TemporalType enumeration. This offers three possible values: DATE, TIME, and TIMESTAMP. These correspond respectively to java.sql.Date, java.sql.Time, and java.sql.Timestamp. The table column is given the appropriate data type at schema generation time. Listing 6-26 shows an example mapping a java.util.Date property as a TIME type the java.sql.Date and java.sql.Time classes are both derived from the java.util.Date class, so confusingly, both are capable of representing dates and times! Listing 6-26. A Date Property Mapped as a Time Temporal Field @Temporal(TIME) public java.util.Date getStartingTime() { return this.startingTime; }
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision best web hosting services