108 CHAPTER 6 n MAPPING WITH ANNOTATIONS CHAPTER (Mac os x web server)
Friday, April 20th, 2007108 CHAPTER 6 n MAPPING WITH ANNOTATIONS CHAPTER 6 n MAPPING WITH ANNOTATIONS public Account(String description) { this.description = description; } protected Account() { } @EmbeddedId public AccountPk getId() { return this.id; } public String getDescription() { return this.description; } public void setId(AccountPk id) { this.id = id; } public void setDescription(String description) { this.description = description; } public static class AccountPk { // … } } Finally, the use of the @IdClass and @Idannotations allows us to map the compound primary key class using properties of the entity itself corresponding to the names of the properties in the primary key class. The names must correspond (there is no mechanism for overriding this), and the primary key class must honor the same obligations as with the other two techniques. The only advantage to this approach is its ability to hide the use of the primary key class from the interface of the enclosing entity. The @IdClassannotation takes a value parameter of Classtype, which must be the class to be used as the compound primary key. The fields that correspond to the properties of the primary key class to be used must all be annotated with @Id note in Listing 6-8 that the getCode() and getNumber()methods of the Accountclass are so annotated, and the AccountPkclass is not mapped as @Embeddable, but it is supplied as the value of the @IdClass annotation.
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision ftp web hosting services