Skip to content

Commit 0b70ef5

Browse files
authored
Jakarta Persistence 3.2 - Allows usage of TableGenerator and SequenceGenerator at the java package level (#2544)
Implementation and unit tests Signed-off-by: Radek Felcman <[email protected]>
1 parent 6a8a13a commit 0b70ef5

File tree

12 files changed

+543
-10
lines changed

12 files changed

+543
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
*/
12+
package org.eclipse.persistence.testing.models.jpa.persistence32;
13+
14+
import jakarta.persistence.Entity;
15+
import jakarta.persistence.GeneratedValue;
16+
import jakarta.persistence.Id;
17+
import jakarta.persistence.Table;
18+
19+
import java.util.Objects;
20+
21+
import static jakarta.persistence.GenerationType.TABLE;
22+
23+
@Entity
24+
@Table(name = "PERSISTENCE32_SEQUENCE_GEN_PCKG_ENTITY")
25+
public class SequenceGeneratorPackageScopeEntity {
26+
27+
private int id;
28+
private String name;
29+
30+
@Id
31+
@GeneratedValue(strategy=TABLE, generator = "SequenceGeneratorPackageScope")
32+
public int getId() {
33+
return id;
34+
}
35+
36+
public void setId(int id) {
37+
this.id = id;
38+
}
39+
40+
public String getName() {
41+
return name;
42+
}
43+
44+
public void setName(String name) {
45+
this.name = name;
46+
}
47+
48+
@Override
49+
public boolean equals(Object o) {
50+
if (o == null || getClass() != o.getClass()) return false;
51+
SequenceGeneratorPackageScopeEntity that = (SequenceGeneratorPackageScopeEntity) o;
52+
return id == that.id && Objects.equals(name, that.name);
53+
}
54+
55+
@Override
56+
public int hashCode() {
57+
return Objects.hash(id, name);
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
*/
12+
package org.eclipse.persistence.testing.models.jpa.persistence32;
13+
14+
import jakarta.persistence.Entity;
15+
import jakarta.persistence.GeneratedValue;
16+
import jakarta.persistence.Id;
17+
import jakarta.persistence.Table;
18+
19+
import java.util.Objects;
20+
21+
import static jakarta.persistence.GenerationType.TABLE;
22+
23+
@Entity
24+
@Table(name = "PERSISTENCE32_SEQUENCE_GEN_PCKG_ENTITY1")
25+
public class SequenceGeneratorWithoutNamePackageScopeEntity {
26+
27+
private int id;
28+
private String name;
29+
30+
@Id
31+
@GeneratedValue(strategy=TABLE)
32+
public int getId() {
33+
return id;
34+
}
35+
36+
public void setId(int id) {
37+
this.id = id;
38+
}
39+
40+
public String getName() {
41+
return name;
42+
}
43+
44+
public void setName(String name) {
45+
this.name = name;
46+
}
47+
48+
@Override
49+
public boolean equals(Object o) {
50+
if (o == null || getClass() != o.getClass()) return false;
51+
SequenceGeneratorWithoutNamePackageScopeEntity that = (SequenceGeneratorWithoutNamePackageScopeEntity) o;
52+
return id == that.id && Objects.equals(name, that.name);
53+
}
54+
55+
@Override
56+
public int hashCode() {
57+
return Objects.hash(id, name);
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
*/
12+
package org.eclipse.persistence.testing.models.jpa.persistence32;
13+
14+
import jakarta.persistence.Entity;
15+
import jakarta.persistence.GeneratedValue;
16+
import jakarta.persistence.Id;
17+
import jakarta.persistence.Table;
18+
19+
import java.util.Objects;
20+
21+
import static jakarta.persistence.GenerationType.TABLE;
22+
23+
@Entity
24+
@Table(name = "PERSISTENCE32_TABLE_GEN_PCKG_ENTITY")
25+
public class TableGeneratorPackageScopeEntity {
26+
27+
private int id;
28+
private String name;
29+
30+
@Id
31+
@GeneratedValue(strategy=TABLE, generator = "TableGeneratorPackageScope")
32+
public int getId() {
33+
return id;
34+
}
35+
36+
public void setId(int id) {
37+
this.id = id;
38+
}
39+
40+
public String getName() {
41+
return name;
42+
}
43+
44+
public void setName(String name) {
45+
this.name = name;
46+
}
47+
48+
@Override
49+
public boolean equals(Object o) {
50+
if (o == null || getClass() != o.getClass()) return false;
51+
TableGeneratorPackageScopeEntity that = (TableGeneratorPackageScopeEntity) o;
52+
return id == that.id && Objects.equals(name, that.name);
53+
}
54+
55+
@Override
56+
public int hashCode() {
57+
return Objects.hash(id, name);
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
*/
12+
package org.eclipse.persistence.testing.models.jpa.persistence32;
13+
14+
import jakarta.persistence.Entity;
15+
import jakarta.persistence.GeneratedValue;
16+
import jakarta.persistence.Id;
17+
import jakarta.persistence.Table;
18+
19+
import java.util.Objects;
20+
21+
import static jakarta.persistence.GenerationType.TABLE;
22+
23+
@Entity
24+
@Table(name = "PERSISTENCE32_TABLE_GEN_PCKG_ENTITY1")
25+
public class TableGeneratorWithoutNamePackageScopeEntity {
26+
27+
private int id;
28+
private String name;
29+
30+
@Id
31+
@GeneratedValue(strategy=TABLE)
32+
public int getId() {
33+
return id;
34+
}
35+
36+
public void setId(int id) {
37+
this.id = id;
38+
}
39+
40+
public String getName() {
41+
return name;
42+
}
43+
44+
public void setName(String name) {
45+
this.name = name;
46+
}
47+
48+
@Override
49+
public boolean equals(Object o) {
50+
if (o == null || getClass() != o.getClass()) return false;
51+
TableGeneratorWithoutNamePackageScopeEntity that = (TableGeneratorWithoutNamePackageScopeEntity) o;
52+
return id == that.id && Objects.equals(name, that.name);
53+
}
54+
55+
@Override
56+
public int hashCode() {
57+
return Objects.hash(id, name);
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
*/
12+
@TableGenerators({
13+
@TableGenerator(
14+
name = "TableGeneratorPackageScope",
15+
table = "PERSISTENCE32_TABLE_PCKG_GENERATOR",
16+
pkColumnName = "SEQ_NAME",
17+
valueColumnName = "SEQ_COUNT"
18+
),
19+
@TableGenerator(
20+
table = "PERSISTENCE32_TABLE_PCKG_GENERATOR1",
21+
pkColumnName = "SEQ_NAME",
22+
valueColumnName = "SEQ_COUNT"
23+
)
24+
})
25+
@SequenceGenerators({
26+
@SequenceGenerator(
27+
name = "SequenceGeneratorPackageScope",
28+
sequenceName = "PERSISTENCE32_SEQUENCE_PCKG_GENERATOR",
29+
allocationSize = 1
30+
),
31+
@SequenceGenerator(
32+
sequenceName = "PERSISTENCE32_SEQUENCE_PCKG_GENERATOR1",
33+
allocationSize = 1
34+
)
35+
})
36+
37+
package org.eclipse.persistence.testing.models.jpa.persistence32;
38+
39+
import jakarta.persistence.SequenceGenerator;
40+
import jakarta.persistence.SequenceGenerators;
41+
import jakarta.persistence.TableGenerator;
42+
import jakarta.persistence.TableGenerators;
43+

jpa/eclipselink.jpa.testapps/jpa.test.persistence32/src/main/resources/META-INF/persistence.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@
2828
<class>org.eclipse.persistence.testing.models.jpa.persistence32.SyntaxEntity</class>
2929
<class>org.eclipse.persistence.testing.models.jpa.persistence32.VersionEntity</class>
3030
<class>org.eclipse.persistence.testing.models.jpa.persistence32.InnerEntitiesContainer$InnerTeamEntity</class>
31-
<class>org.eclipse.persistence.testing.models.jpa.persistence32.TableGeneratorEntity</class>
3231
<class>org.eclipse.persistence.testing.models.jpa.persistence32.SequenceGeneratorEntity</class>
32+
<class>org.eclipse.persistence.testing.models.jpa.persistence32.SequenceGeneratorPackageScopeEntity</class>
33+
<class>org.eclipse.persistence.testing.models.jpa.persistence32.SequenceGeneratorWithoutNamePackageScopeEntity</class>
34+
<class>org.eclipse.persistence.testing.models.jpa.persistence32.TableGeneratorEntity</class>
35+
<class>org.eclipse.persistence.testing.models.jpa.persistence32.TableGeneratorPackageScopeEntity</class>
36+
<class>org.eclipse.persistence.testing.models.jpa.persistence32.TableGeneratorWithoutNamePackageScopeEntity</class>
3337
<exclude-unlisted-classes>true</exclude-unlisted-classes>
3438
<properties>
3539
<property name="jakarta.persistence.schema-generation.scripts.action" value="none"/>

jpa/eclipselink.jpa.testapps/jpa.test.persistence32/src/test/java/org/eclipse/persistence/testing/tests/jpa/persistence32/SchemaManagerValidateOnMissingSchemaTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ public void testValidateOnMissingSchema() {
6161
"PERSISTENCE32_SE_COLTABLE",
6262
"PERSISTENCE32_INNER_TEAM",
6363
"PERSISTENCE32_SEQUENCE_GEN_ENTITY",
64-
"PERSISTENCE32_TABLE_GEN_ENTITY"
64+
"PERSISTENCE32_SEQUENCE_GEN_PCKG_ENTITY",
65+
"PERSISTENCE32_SEQUENCE_GEN_PCKG_ENTITY1",
66+
"PERSISTENCE32_TABLE_GEN_ENTITY",
67+
"PERSISTENCE32_TABLE_GEN_PCKG_ENTITY",
68+
"PERSISTENCE32_TABLE_GEN_PCKG_ENTITY1"
6569
};
6670
Set<String> missingTablesSet = new HashSet<>(Arrays.asList(missingTables));
6771
Set<String> initialMissingTablesSet = Set.copyOf(missingTablesSet);

0 commit comments

Comments
 (0)