CHAPTER 6 (How to cite a web site) n MAPPING WITH ANNOTATIONS 129 n

CHAPTER 6 n MAPPING WITH ANNOTATIONS 129 n MAPPING WITH ANNOTATIONS 129 mutable is true by default, but if set to false, it allows the persistence engine to cache the values read from the database, and the persistence engine will make no attempt to update them in response to changes (changes that should not be made if this flag is set to false). optimisticLock allows an optimistic lock strategy to be selected from the OptimisticLockType enumeration values of ALL, DIRTY, NONE, and VERSION. This defaults to VERSION. persister allows a persister class other than the default Hibernate one to be selected for the entity (for example, allowing serialization to be used instead of relational persistence). polymorphism allows the polymorphism strategy to be selected from the PolymorphismType enumeration values of EXPLICIT and IMPLICIT. This defaults to IMPLICIT. selectBeforeUpdate allows the user to request that a SELECT be performed to retrieve the entity before any potential update. Sorting Collections with @Sort The Hibernate-specific @Sort annotation allows a collection managed by Hibernate to be sorted by a standard Java comparator. The following code gives an example. @javac.persistence.OneToMany @org.hibernate.annotations.Sort( type=org.hibernate.annotations.SortType.COMPARATOR, comparator=EmployeeComparator.class ) public Set getEmployees() { return this.employees; } Ordering Collections with @IndexColumn While @Sort allows data to be sorted once it has been retrieved from the database, Hibernate also provides a non-standard persistence feature that allows the ordering of appropriate collection types such as List to be maintained within the database by maintaining an index column to represent that order. Here s an example: @javax.persistence.OneToMany @org.hibernate.annotations.IndexColumn( name=”employeeNumber” ) public List getEmployees() { return this.employees; } Here, we are declaring that an employeeNumbercolumn will maintain a value, starting at 0 and incrementing as each entry is added to the list. The default starting value can be overridden by the baseattribute. By default, the column can contain null (unordered) values. This can be overridden by setting the nullableattribute to false. By default, when the schema is generated
Note: If you are looking for high quality webhost to host and run your jsp application check Vision christian web host services

Leave a Reply