Skip to content

Commit d49f704

Browse files
committed
HBX-3000: Maven GenerateJava Mojo should generate annotated entities by default
- Add file 'invoker.properties' for GenerateJavaWithAnnotations to only execute phase 'generate-resources' - Modify 'setup.bsh' for GenerateJavaWithAnnotations to create test database in basedir - Add file 'hibernate.properties' for GenerateJavaWithAnnotations so that the Person entity is generated - Modify 'verify.bsh' to verify that the Person entity is generated properly with annotations Signed-off-by: Koen Aers <[email protected]>
1 parent 0d05967 commit d49f704

File tree

4 files changed

+89
-8
lines changed

4 files changed

+89
-8
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
############################################################################
2+
# Hibernate Tools, Tooling for your Hibernate Projects #
3+
# #
4+
# Copyright 2018-2025 Red Hat, Inc. #
5+
# #
6+
# Licensed under the Apache License, Version 2.0 (the "License"); #
7+
# you may not use this file except in compliance with the License. #
8+
# You may obtain a copy of the License at #
9+
# #
10+
# http://www.apache.org/licenses/LICENSE-2.0 #
11+
# #
12+
# Unless required by applicable law or agreed to in writing, software #
13+
# distributed under the License is distributed on an "AS IS" basis, #
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15+
# See the License for the specific language governing permissions and #
16+
# limitations under the License. #
17+
############################################################################
18+
invoker.goals = generate-resources
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
/*
2+
* Hibernate Tools, Tooling for your Hibernate Projects
3+
*
4+
* Copyright 2018-2025 Red Hat, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" basis,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
118
import java.sql.DriverManager;
219
import java.sql.Connection;
320

4-
String JDBC_CONNECTION = "jdbc:h2:mem:test";
21+
String JDBC_CONNECTION = "jdbc:h2:" + basedir + "/test";
522
String CREATE_PERSON_TABLE = "create table PERSON (ID int not null, NAME varchar(20), primary key (ID))";
623

7-
DriverManager
8-
.getConnection(JDBC_CONNECTION)
9-
.createStatement()
10-
.execute(CREATE_PERSON_TABLE);
11-
12-
System.out.println("Database created!");
24+
Connection connection = DriverManager.getConnection(JDBC_CONNECTION);
25+
connection.createStatement().execute(CREATE_PERSON_TABLE);
26+
connection.close();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
############################################################################
2+
# Hibernate Tools, Tooling for your Hibernate Projects #
3+
# #
4+
# Copyright 2018-2025 Red Hat, Inc. #
5+
# #
6+
# Licensed under the Apache License, Version 2.0 (the "License"); #
7+
# you may not use this file except in compliance with the License. #
8+
# You may obtain a copy of the License at #
9+
# #
10+
# http://www.apache.org/licenses/LICENSE-2.0 #
11+
# #
12+
# Unless required by applicable law or agreed to in writing, software #
13+
# distributed under the License is distributed on an "AS IS" basis, #
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15+
# See the License for the specific language governing permissions and #
16+
# limitations under the License. #
17+
############################################################################
18+
hibernate.connection.driver_class=org.h2.Driver
19+
hibernate.connection.url=jdbc:h2:./test
20+
hibernate.default_catalog=TEST
21+
hibernate.default_schema=PUBLIC
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
1-
System.out.println("Hello from 'verify.bsh'");
1+
/*
2+
* Hibernate Tools, Tooling for your Hibernate Projects
3+
*
4+
* Copyright 2018-2025 Red Hat, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" basis,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
import java.nio.file.Files;
19+
20+
File personEntity = new File(basedir, "target/generated-sources/Person.java");
21+
if (!personEntity.isFile()) {
22+
throw new FileNotFoundException("Could not find generated JPA Entity: " + personEntity);
23+
}
24+
byte[] raw = Files.readAllBytes(personEntity.toPath());
25+
if (!new String(raw).contains("import jakarta.persistence.Entity;")) {
26+
throw new RuntimeException("The generated java file is not a JPA Entity");
27+
}
28+
29+

0 commit comments

Comments
 (0)