Skip to content

Commit

Permalink
Make the name member of @XxxxGenerator annotations optional
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed May 25, 2023
1 parent e498c21 commit c3c1b77
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
17 changes: 12 additions & 5 deletions api/src/main/java/jakarta/persistence/GeneratedValue.java
Expand Up @@ -13,6 +13,7 @@
// Contributors:
// Linda DeMichiel - 2.1
// Linda DeMichiel - 2.0
// Gavin King - 3.2

package jakarta.persistence;

Expand All @@ -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 <code>GeneratedValue</code> 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
* <code>GeneratedValue</code> annotation is not supported for derived
* primary keys.
*
Expand Down Expand Up @@ -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.
* <p> 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.
* <p> The name defaults to the entity name of the
* entity in which the annotation occurs.
* <p> 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 "";
}
11 changes: 9 additions & 2 deletions api/src/main/java/jakarta/persistence/SequenceGenerator.java
Expand Up @@ -14,6 +14,7 @@
// Lukas Jungmann - 2.2
// Linda DeMichiel - 2.1
// Linda DeMichiel - 2.0
// Gavin King - 3.2

package jakarta.persistence;

Expand All @@ -34,6 +35,10 @@
* generator name is global to the persistence unit (across all
* generator types).
*
* <p> 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.
*
* <pre>
* Example:
*
Expand All @@ -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.
* <p> 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
Expand Down
22 changes: 14 additions & 8 deletions api/src/main/java/jakarta/persistence/TableGenerator.java
Expand Up @@ -14,7 +14,7 @@
// Lukas Jungmann - 2.2
// Linda DeMichiel - 2.1
// Linda DeMichiel - 2.0

// Gavin King - 3.2

package jakarta.persistence;

Expand All @@ -35,14 +35,19 @@
* field or property. The scope of the generator name is global
* to the persistence unit (across all generator types).
*
* <p> 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.
*
* <pre>
* Example 1:
*
* &#064;Entity public class Employee {
* ...
* &#064;TableGenerator(
* name="empGen",
* table="ID_GEN",
* name="empGen",
* table="ID_GEN",
* pkColumnName="GEN_KEY",
* valueColumnName="GEN_VALUE",
* pkColumnValue="EMP_ID",
Expand All @@ -58,13 +63,12 @@
* &#064;Entity public class Address {
* ...
* &#064;TableGenerator(
* name="addressGen",
* table="ID_GEN",
* table="ID_GEN",
* pkColumnName="GEN_KEY",
* valueColumnName="GEN_VALUE",
* pkColumnValue="ADDR_ID")
* &#064;Id
* &#064;GeneratedValue(strategy=TABLE, generator="addressGen")
* &#064;GeneratedValue(strategy=TABLE)
* int id;
* ...
* }
Expand All @@ -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.
* <p> 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.
Expand Down

0 comments on commit c3c1b77

Please sign in to comment.