diff --git a/maven/src/it/use-generics/invoker.properties b/maven/src/it/use-generics/invoker.properties new file mode 100644 index 0000000000..27e586ee24 --- /dev/null +++ b/maven/src/it/use-generics/invoker.properties @@ -0,0 +1,18 @@ +############################################################################ +# Hibernate Tools, Tooling for your Hibernate Projects # +# # +# Copyright 2018-2025 Red Hat, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" basis, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################ +invoker.goals = generate-resources \ No newline at end of file diff --git a/maven/src/it/use-generics/pom.xml b/maven/src/it/use-generics/pom.xml new file mode 100644 index 0000000000..3f86642218 --- /dev/null +++ b/maven/src/it/use-generics/pom.xml @@ -0,0 +1,53 @@ + + + + 4.0.0 + + org.hibernate.tool.maven.test + use-generics + 0.0.1-SNAPSHOT + + + + com.h2database + h2 + @h2.version@ + + + + + + + org.hibernate.tool + hibernate-tools-maven + @project.version@ + + + Entity generation + generate-sources + + hbm2java + + + + + + + + \ No newline at end of file diff --git a/maven/src/it/use-generics/setup.bsh b/maven/src/it/use-generics/setup.bsh new file mode 100644 index 0000000000..b4b5a472c6 --- /dev/null +++ b/maven/src/it/use-generics/setup.bsh @@ -0,0 +1,34 @@ +/* + * Hibernate Tools, Tooling for your Hibernate Projects + * + * Copyright 2018-2025 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.sql.DriverManager; +import java.sql.Connection; +import java.sql.Statement; + +String JDBC_CONNECTION = "jdbc:h2:" + basedir + "/test"; +String CREATE_PERSON_TABLE = + "create table PERSON (ID int not null, NAME varchar(20), primary key (ID))"; +String CREATE_ITEM_TABLE = + "create table ITEM (ID int not null, NAME varchar(20), OWNER_ID int not null, " + + " primary key (ID), foreign key (OWNER_ID) references PERSON(ID))"; + +Connection connection = DriverManager.getConnection(JDBC_CONNECTION); +Statement statement = connection.createStatement(); +statement.execute(CREATE_PERSON_TABLE); +statement.execute(CREATE_ITEM_TABLE); +statement.close(); +connection.close(); diff --git a/maven/src/it/use-generics/src/main/resources/hibernate.properties b/maven/src/it/use-generics/src/main/resources/hibernate.properties new file mode 100644 index 0000000000..32da3e5d10 --- /dev/null +++ b/maven/src/it/use-generics/src/main/resources/hibernate.properties @@ -0,0 +1,21 @@ +############################################################################ +# Hibernate Tools, Tooling for your Hibernate Projects # +# # +# Copyright 2018-2025 Red Hat, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" basis, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:./test +hibernate.default_catalog=TEST +hibernate.default_schema=PUBLIC \ No newline at end of file diff --git a/maven/src/it/use-generics/verify.bsh b/maven/src/it/use-generics/verify.bsh new file mode 100644 index 0000000000..ddc33e4437 --- /dev/null +++ b/maven/src/it/use-generics/verify.bsh @@ -0,0 +1,29 @@ +/* + * Hibernate Tools, Tooling for your Hibernate Projects + * + * Copyright 2018-2025 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.nio.file.Files; + +File personEntity = new File(basedir, "target/generated-sources/Person.java"); +if (!personEntity.isFile()) { + throw new FileNotFoundException("Could not find generated Java file: " + personEntity); +} +byte[] raw = Files.readAllBytes(personEntity.toPath()); +if (!new String(raw).contains("Set")) { + throw new RuntimeException("The generated Java file should use generics"); +} + + diff --git a/maven/src/main/java/org/hibernate/tool/maven/GenerateJavaMojo.java b/maven/src/main/java/org/hibernate/tool/maven/GenerateJavaMojo.java index f496301d02..f8b3e35056 100644 --- a/maven/src/main/java/org/hibernate/tool/maven/GenerateJavaMojo.java +++ b/maven/src/main/java/org/hibernate/tool/maven/GenerateJavaMojo.java @@ -51,7 +51,7 @@ public class GenerateJavaMojo extends AbstractGenerationMojo { private boolean ejb3; /** Code will contain JDK 5 constructs such as generics and static imports. */ - @Parameter(defaultValue = "false") + @Parameter(defaultValue = "true") private boolean jdk5; /** A path used for looking up user-edited templates. */