You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then any entity in this package which specifies `strategy=SEQUENCE` or `strategy=TABLE` without also explicitly specifying a generator `name` will be assigned a generator based on the package-level annotation.
314
+
315
+
[source,java]
316
+
----
317
+
@Id
318
+
@GeneratedValue(strategy=SEQUENCE) // uses the sequence generator defined at the package level
319
+
Long id;
320
+
----
321
+
322
+
// [NOTE]
323
+
// // .JPA id generators may be shared between entities
324
+
// ====
325
+
// JPA id generators may be shared between entities.
326
+
// A `@SequenceGenerator` or `@TableGenerator` must have a name, and may be shared between multiple id attributes.
327
+
// This fits somewhat uncomfortably with the common practice of annotating the `@Id` attribute which makes use of the generator!
328
+
// ====
309
329
310
330
As you can see, JPA provides quite adequate support for the most common strategies for system-generated ids.
311
331
However, the annotations themselves are a bit more intrusive than they should be, and there's no well-defined way to extend this framework to support custom strategies for id generation.
0 commit comments