Anyway, the old syntax for @Id annotation allowed atributes for specifying Id Generators. The new method requires the Id Generator to be specified separately using a @GeneratedValue annotation. Here is a comparison between the old approach and the new approach:
Old approach:
@Id (generate=GeneratorType.SEQUENCE, generator="SEQ_GEN")New approach:
public Long id;
@IdI think the new approach is cleaner. It also enables Id Generator to be used in fields that are not necessarily the primary key.
@GeneratedValue(strategy=GenerationType.SEQUENCE,
generator="SEQ_GEN")
public Long id;
Overall, the fact that Glassfish seems to be following the draft specification closely is great, as it enables developers to get familiar with the new technology. Thankfully, the specs are now close to final version, so changes ought to be relatively small.
Talking of changes, I hit another one. The syntax for @TableGenerator has changed. The table is not longer specified using @Table, instead, table and schema are ordinary string attributes. Here's an example of the new syntax:
@TableGenerator(name = "DISTRICT_ID_SEQUENCE",
table = "IDGENERATOR", schema = "TPCC",
pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT",
pkColumnValue = "DISTRICT_ID_SEQUENCE",
allocationSize = 10)
No comments:
Post a Comment