diff --git a/api/src/main/java/jakarta/persistence/GeneratedValue.java b/api/src/main/java/jakarta/persistence/GeneratedValue.java
index 41778e88..bddbef0a 100644
--- a/api/src/main/java/jakarta/persistence/GeneratedValue.java
+++ b/api/src/main/java/jakarta/persistence/GeneratedValue.java
@@ -11,6 +11,7 @@
*/
// Contributors:
+// Gavin King - 3.2
// Linda DeMichiel - 2.1
// Linda DeMichiel - 2.0
@@ -31,7 +32,7 @@
* may be applied to a primary key property or field of an entity or
* mapped superclass in conjunction with the {@link Id} annotation.
* The use of the GeneratedValue
annotation is only
- * required to be supported for simple primary keys. Use of the
+ * required to be supported for simple primary keys. Use of the
* GeneratedValue
annotation is not supported for derived
* primary keys.
*
@@ -71,10 +72,16 @@
GenerationType strategy() default AUTO;
/**
- * (Optional) The name of the primary key generator
- * to use as specified in the {@link SequenceGenerator}
- * or {@link TableGenerator} annotation.
- *
Defaults to the id generator supplied by persistence provider. + * (Optional) The name of the primary key generator to + * use, as specified by the {@link SequenceGenerator} + * or {@link TableGenerator} annotation which declares + * the generator. + *
The name defaults to the entity name of the + * entity in which the annotation occurs. + *
If there is no generator with the defaulted + * name, then the persistence provider supplies a + * default id generator, of a type compatible with + * the value of the strategy member. */ String generator() default ""; } diff --git a/api/src/main/java/jakarta/persistence/SequenceGenerator.java b/api/src/main/java/jakarta/persistence/SequenceGenerator.java index 181ff5f9..199dcafb 100644 --- a/api/src/main/java/jakarta/persistence/SequenceGenerator.java +++ b/api/src/main/java/jakarta/persistence/SequenceGenerator.java @@ -11,6 +11,7 @@ */ // Contributors: +// Gavin King - 3.2 // Lukas Jungmann - 2.2 // Linda DeMichiel - 2.1 // Linda DeMichiel - 2.0 @@ -34,6 +35,10 @@ * generator name is global to the persistence unit (across all * generator types). * + *
If no name is explicitly specified, and the annotation occurs + * on an entity class or primary key attribute of an entity class, + * then the name defaults to the name of the entity. + * *
* Example: * @@ -48,11 +53,13 @@ public @interface SequenceGenerator { /** - * (Required) A unique generator name that can be referenced + * (Optional) A unique generator name that can be referenced * by one or more classes to be the generator for primary key * values. + *Defaults to the name of the entity when the annotation + * occurs on an entity class or primary key attribute. */ - String name(); + String name() default ""; /** * (Optional) The name of the database sequence object from diff --git a/api/src/main/java/jakarta/persistence/TableGenerator.java b/api/src/main/java/jakarta/persistence/TableGenerator.java index 2c2ea33f..54be06c6 100644 --- a/api/src/main/java/jakarta/persistence/TableGenerator.java +++ b/api/src/main/java/jakarta/persistence/TableGenerator.java @@ -11,11 +11,11 @@ */ // Contributors: +// Gavin King - 3.2 // Lukas Jungmann - 2.2 // Linda DeMichiel - 2.1 // Linda DeMichiel - 2.0 - package jakarta.persistence; import java.lang.annotation.Target; @@ -35,6 +35,11 @@ * field or property. The scope of the generator name is global * to the persistence unit (across all generator types). * + *
If no name is explicitly specified, and the annotation + * occurs on an entity class or primary key attribute of an + * entity class, then the name defaults to the name of the + * entity. + * *
* Example 1: * @@ -42,7 +47,7 @@ * ... * @TableGenerator( * name="empGen", - * table="ID_GEN", + * table="ID_GEN", * pkColumnName="GEN_KEY", * valueColumnName="GEN_VALUE", * pkColumnValue="EMP_ID", @@ -58,13 +63,12 @@ * @Entity public class Address { * ... * @TableGenerator( - * name="addressGen", - * table="ID_GEN", + * table="ID_GEN", * pkColumnName="GEN_KEY", * valueColumnName="GEN_VALUE", * pkColumnValue="ADDR_ID") * @Id - * @GeneratedValue(strategy=TABLE, generator="addressGen") + * @GeneratedValue(strategy=TABLE) * int id; * ... * } @@ -80,10 +84,12 @@ public @interface TableGenerator { /** - * (Required) A unique generator name that can be referenced + * (optional) A unique generator name that can be referenced * by one or more classes to be the generator for id values. + *Defaults to the name of the entity when the annotation + * occurs on an entity class or primary key attribute. */ - String name(); + String name() default ""; /** * (Optional) Name of table that stores the generated id values. diff --git a/spec/src/main/asciidoc/appendixes.adoc b/spec/src/main/asciidoc/appendixes.adoc index aa7490a6..6e2ab49e 100644 --- a/spec/src/main/asciidoc/appendixes.adoc +++ b/spec/src/main/asciidoc/appendixes.adoc @@ -111,3 +111,6 @@ Added `||` string concatenation operator Added _getSingleResultOrNull()_ to _Query_, _TypedQuery_, _StoredProcedureQuery_ Added _concat()_ overload accepting list of expressions to _CriteriaBuilder_ + +Made the _name_ member of _TableGenerator_ and _SequenceGenerator_ optional + diff --git a/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc b/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc index 479bc70a..76a39bb9 100644 --- a/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc +++ b/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc @@ -4687,6 +4687,11 @@ generator may be specified on the entity class or on the primary key field or property. The scope of the generator name is global to the persistence unit (across all generator types). +If no name is explicitly specified by the _SequenceGenerator_ annotation, +and the annotation occurs on an entity class or primary key attribute of +an entity class, then the name defaults to the name of the entity. +Otherwise, if the annotation occurs elsewhere, the behavior is undefined. + <
> lists the annotation elements that may be specified for the _SequenceGenerator_ annotation and their default values. @@ -4697,7 +4702,7 @@ default values. @Retention(RUNTIME) @Repeatable(SequenceGenerators.class) public @interface SequenceGenerator { - String name(); + String name() default ""; String sequenceName() default ""; String catalog() default ""; String schema() default ""; @@ -4864,6 +4869,11 @@ generator may be specified on the entity class or on the primary key field or property. The scope of the generator name is global to the persistence unit (across all generator types). +If no name is explicitly specified by the _TableGenerator_ annotation, +and the annotation occurs on an entity class or primary key attribute +of an entity class, then the name defaults to the name of the entity. +Otherwise, if the annotation occurs elsewhere, the behavior is undefined. + < > lists the annotation elements that may be specified for the _TableGenerator_ annotation and their default values. @@ -4880,7 +4890,7 @@ primary key values are normally positive integers. @Retention(RUNTIME) @Repeatable(TableGenerators.class) public @interface TableGenerator { - String name(); + String name() default ""; String table() default ""; String catalog() default ""; String schema() default ""; diff --git a/spec/src/main/asciidoc/ch12-xml-or-mapping-descriptor.adoc b/spec/src/main/asciidoc/ch12-xml-or-mapping-descriptor.adoc index 9cfeb769..77ae4ae4 100644 --- a/spec/src/main/asciidoc/ch12-xml-or-mapping-descriptor.adoc +++ b/spec/src/main/asciidoc/ch12-xml-or-mapping-descriptor.adoc @@ -3048,7 +3048,7 @@ object/relational mapping schema for use with the persistence API. @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface SequenceGenerator { - String name(); + String name() default ""; String sequenceName() default ""; String catalog() default ""; String schema() default ""; @@ -3157,7 +3157,7 @@ object/relational mapping schema for use with the persistence API. @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface TableGenerator { - String name(); + String name() default ""; String table() default ""; String catalog() default ""; String schema() default "";