Make my own web site - 130 CHAPTER 6 n MAPPING WITH ANNOTATIONS CHAPTER

130 CHAPTER 6 n MAPPING WITH ANNOTATIONS CHAPTER 6 n MAPPING WITH ANNOTATIONS from the annotations, the column is assumed to be an integertype, but this can be overridden by supplying a columnDefinitionattribute specifying a different column definition string. Applying Indexes with @Table and @Index The Hibernate-specific @Table annotation supplements the standard table annotation and allows additional index hints to be provided to Hibernate. These will be used at schema generation time to apply indexes to the columns specified. The following code gives an example. // Standard persistence annotations: @javax.persistence.Entity @javax.persistence.Table(name=”FOO”) // Hibernate-specific table annotation: @Table( appliesTo=”FOO”, indexes = { @Index(name=”FOO_FROM_TO_IDX”,columnNames={”FIRST”,”LAST”}), @Index(name=”FOO_EMPLOYEE_IDX”,columnNames={”EMPLOYEE_NUM”})) public class Foo { … } Restricting Collections with @Where The contents of a collection that will be retrieved from the database can be restricted with a Hibernate-specific @Where annotation. This simply adds a Where clause to the query that will be used to obtain the entities contained within the collection. Here s an example: @javax.persistence.OneToMany @org.hibernate.annotations.Where(clause=”grade > 2″) public Set getEmployees() { return this.employees; } Alternative Key Generation Strategies with @GenericGenerator As mentioned in the Primary Keys with @Id and @GeneratedValue section, the full gamut of Hibernate primary key value generators is not supported by the standard set of annotations. Hibernate therefore supplies the @GenericGenerator annotation to fill the void. The attributes that can be supplied to the annotation are as follows: name is mandatory, and is used to identify the generic generator in the @GeneratedValue annotation. strategy is mandatory, and determines the generator type to be used. This can be a standard Hibernate generator type or the name of a class implementing the org.hibernate. id.IdentifierGenerator interface. parameters is a list of @Parameter annotations defining any parameter values required by the generator strategy.
Note: In case you are looking for affordable webhost to host and run your web application check Vision cheap hosting services

Leave a Reply