104 CHAPTER 6 n MAPPING (Personal web server) WITH ANNOTATIONS CHAPTER
104 CHAPTER 6 n MAPPING WITH ANNOTATIONS CHAPTER 6 n MAPPING WITH ANNOTATIONS Only the sequence generator name is mandatory the other attributes will take sensible default values but you should provide an explicit value for the sequenceNameattribute as a matter of good practice anyway. If not specified, the sequenceName value to be used is selected by the persistence provider (i.e., Hibernate or EJB 3). The other (optional) attributes are initialValue and allocationSize, which default to values of 1 and 50, respectively. Generating Primary Key Values with @TableGenerator The @TableGenerator annotation is used in a very similar way to the @SequenceGenerator annotation but because @TableGenerator manipulates a standard database table to obtain its primary key values, instead of using a vendor-specific sequence object, it is guaranteed to be portable between database platforms. nNote For optimal portability and optimal performance, you should not specify the use of a table generator, but instead use the @GeneratorValue(strategy=GeneratorType.AUTO) configuration, which allows the persistence provider to select the most appropriate strategy for the database in use. As with the sequence generator, the name attributes of @TableGenerator are mandatory and the other attributes are optional, with the table details being selected by the persistence provider. @Id @TableGenerator(name=”tablegen”, table=”ID_TABLE”, pkColumnName=”ID”, valueColumnName=”NEXT_ID”) @GeneratedValue(strategy=TABLE,generator=”tablegen”) public int getId() { return id; } The optional attributes are as follows: allocationSize: Allows the increment on the primary key value to be specified. catalog: Allows the catalog that the table resides within to be specified. initialValue: Allows the starting primary key value to be specified. pkColumnName: Allows the primary key column of the table to be identified. The table can contain the details necessary for generating primary key values for multiple entities. pkColumnValue: Allows the primary key for the row containing the primary key generation information to be identified.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision j2ee hosting services