Shared web hosting - CHAPTER 6 n MAPPING WITH ANNOTATIONS 131 n

CHAPTER 6 n MAPPING WITH ANNOTATIONS 131 n MAPPING WITH ANNOTATIONS 131 The available standard Hibernate strategies are increment, identity, sequence, hilo, seqhilo, uuid, guid, native, assigned, select, and foreign. For example, the non-standard uuid strategy for a primary key is configured as follows: @Id @GenericGenerator(name=”unique_id”,strategy=”uuid”) @GeneratedValue(generator=”unique_id”) public String getId() { return this.id; } Alternatively, to configure the sequence strategy (equivalent to specifying a strategy of SEQUENCE in the @GeneratedValueannotation), you can supply the following parameters: @Id @GenericGenerator(name=”seq_id”,strategy=”sequence”, parameters= { @Parameter(name=”sequence”,value=”HIB_SEQ”) } ) @GeneratedValue(generator=”seq_id”) public Integer getId() { return this.id; } Using Ant with Annotation-Based Mappings When using the Hibernate Ant tasks in conjunction with the annotation-based mappings, you operate under one important constraint: the Ant task cannot read the mapping information from the raw source files. The annotated files must be compiled before you can perform any operations on them (including schema generation). You should therefore ensure that any Hibernate Ant tasks are granted a dependency upon the compile task for the entities. The Ant task will also need access to the classes via the configuration object you will therefore need to explicitly include any annotated classes in the hibernate.cfg.xmlfile as described in the first part of the previous Configuring the Annotated Classes section. You cannot use programmatic configuration of the classes in conjunction with tasks such as hbm2ddl, so this is an important step. The various Hibernate JAR files, including hibernate-annotations.jar, will need to be in the classpath of the task definition. Finally, you will need to specify an element, rather than the usual element. An example Ant target to build a DDL script from annotated classes is shown in Listing 6-33.
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision tomcat hosting services

Leave a Reply