diff --git a/jOOQ-codegen/src/main/java/org/jooq/util/AbstractGenerator.java b/jOOQ-codegen/src/main/java/org/jooq/util/AbstractGenerator.java
index 6b6c91a402..71c0f633b8 100644
--- a/jOOQ-codegen/src/main/java/org/jooq/util/AbstractGenerator.java
+++ b/jOOQ-codegen/src/main/java/org/jooq/util/AbstractGenerator.java
@@ -45,6 +45,7 @@ import java.util.Collections;
import java.util.Set;
import org.jooq.tools.JooqLogger;
+import org.jooq.util.jaxb.JpaVersion;
/**
@@ -100,6 +101,7 @@ abstract class AbstractGenerator implements Generator {
boolean generateEmptyCatalogs = false;
boolean generateEmptySchemas = false;
boolean generatePrimaryKeyTypes = false;
+ JpaVersion generateJpaVersion;
protected GeneratorStrategyWrapper strategy;
protected String targetEncoding = "UTF-8";
@@ -393,6 +395,16 @@ abstract class AbstractGenerator implements Generator {
this.generateJPAAnnotations = generateJPAAnnotations;
}
+ @Override
+ public JpaVersion generateJpaVersion() {
+ return generateJpaVersion;
+ }
+
+ @Override
+ public void setGenerateJpaVersion(JpaVersion generateJpaVersion) {
+ this.generateJpaVersion = generateJpaVersion;
+ }
+
@Override
public boolean generateValidationAnnotations() {
return generateValidationAnnotations;
diff --git a/jOOQ-codegen/src/main/java/org/jooq/util/GenerationTool.java b/jOOQ-codegen/src/main/java/org/jooq/util/GenerationTool.java
index e9cc101484..66913e02e5 100644
--- a/jOOQ-codegen/src/main/java/org/jooq/util/GenerationTool.java
+++ b/jOOQ-codegen/src/main/java/org/jooq/util/GenerationTool.java
@@ -77,6 +77,7 @@ import org.jooq.util.jaxb.Catalog;
import org.jooq.util.jaxb.Configuration;
import org.jooq.util.jaxb.Generate;
import org.jooq.util.jaxb.Jdbc;
+import org.jooq.util.jaxb.JpaVersion;
import org.jooq.util.jaxb.Matchers;
import org.jooq.util.jaxb.Property;
import org.jooq.util.jaxb.Schema;
@@ -555,8 +556,18 @@ public class GenerationTool {
generator.setGenerateImmutableInterfaces(g.getGenerate().isImmutableInterfaces());
if (g.getGenerate().isDaos() != null)
generator.setGenerateDaos(g.getGenerate().isDaos());
- if (g.getGenerate().isJpaAnnotations() != null)
+ if (g.getGenerate().isJpaAnnotations() != null) {
generator.setGenerateJPAAnnotations(g.getGenerate().isJpaAnnotations());
+
+ if (g.getGenerate().getJpaVersion() != null)
+ generator.setGenerateJpaVersion(g.getGenerate().getJpaVersion());
+ else
+ generator.setGenerateJpaVersion(JpaVersion.latest());
+ }
+ else
+ generator.setGenerateJpaVersion(null);
+
+
if (g.getGenerate().isValidationAnnotations() != null)
generator.setGenerateValidationAnnotations(g.getGenerate().isValidationAnnotations());
if (g.getGenerate().isSpringAnnotations() != null)
diff --git a/jOOQ-codegen/src/main/java/org/jooq/util/Generator.java b/jOOQ-codegen/src/main/java/org/jooq/util/Generator.java
index 1af2cbb4b3..8aa9333ff0 100644
--- a/jOOQ-codegen/src/main/java/org/jooq/util/Generator.java
+++ b/jOOQ-codegen/src/main/java/org/jooq/util/Generator.java
@@ -38,6 +38,8 @@
package org.jooq.util;
+import org.jooq.util.jaxb.JpaVersion;
+
import javax.annotation.Generated;
/**
@@ -259,6 +261,16 @@ public interface Generator {
*/
void setGenerateJPAAnnotations(boolean generateJPAAnnotations);
+ /**
+ * Whether used a provided JPA spec version or latest version of it.
+ */
+ JpaVersion generateJpaVersion();
+
+ /**
+ * Whether used a provided JPA spec version or latest version of it.
+ */
+ void setGenerateJpaVersion(JpaVersion generateJpaVersion);
+
/**
* Whether POJO's and records should be annotated with JSR-303 validation
* annotations
diff --git a/jOOQ-codegen/src/main/java/org/jooq/util/JavaGenerator.java b/jOOQ-codegen/src/main/java/org/jooq/util/JavaGenerator.java
index 3c73238389..d084d1c97b 100644
--- a/jOOQ-codegen/src/main/java/org/jooq/util/JavaGenerator.java
+++ b/jOOQ-codegen/src/main/java/org/jooq/util/JavaGenerator.java
@@ -129,6 +129,7 @@ import org.jooq.util.GeneratorStrategy.Mode;
// ...
// ...
// ...
+import org.jooq.util.jaxb.JpaVersion;
import org.jooq.util.postgres.PostgresDatabase;
@@ -278,6 +279,9 @@ public class JavaGenerator extends AbstractGenerator {
+ ((!generateGeneratedAnnotation && (useSchemaVersionProvider || useCatalogVersionProvider)) ?
" (forced to true because of or )" : ""));
log.info(" JPA annotations", generateJPAAnnotations());
+ log.info(" JPA version", generateJpaVersion()
+ + (!generateJPAAnnotations && generateJpaVersion != null ? " (forced to null because of )" :
+ (generateJPAAnnotations && generateJpaVersion == null ? " (forced to " + JpaVersion.latest().name() + " because of )" : "")));
log.info(" validation annotations", generateValidationAnnotations());
log.info(" instance fields", generateInstanceFields());
log.info(" sequences", generateSequences());
@@ -4439,43 +4443,45 @@ public class JavaGenerator extends AbstractGenerator {
out.print(scala ? ")" : "}");
}
- StringBuilder sb2 = new StringBuilder();
- String glue2 = "\n";
+ if (generateJpaVersion() != null && generateJpaVersion().supportedIndex()) {
+ StringBuilder sb2 = new StringBuilder();
+ String glue2 = "\n";
- for (IndexDefinition index : table.getIndexes()) {
- sb2.append(glue2);
- sb2.append("\t")
- .append(scala ? "new " : "@")
- .append(out.ref("javax.persistence.Index"))
- .append("(name = \"").append(index.getOutputName().replace("\"", "\\\"")).append("\"");
+ for (IndexDefinition index : table.getIndexes()) {
+ sb2.append(glue2);
+ sb2.append("\t")
+ .append(scala ? "new " : "@")
+ .append(out.ref("javax.persistence.Index"))
+ .append("(name = \"").append(index.getOutputName().replace("\"", "\\\"")).append("\"");
- if (index.isUnique())
- sb2.append(", unique = true");
+ if (index.isUnique())
+ sb2.append(", unique = true");
- sb2.append(", columnList = \"");
+ sb2.append(", columnList = \"");
- String glue2Inner = "";
- for (IndexColumnDefinition column : index.getIndexColumns()) {
- sb2.append(glue2Inner)
- .append(column.getOutputName().replace("\"", "\\\""));
+ String glue2Inner = "";
+ for (IndexColumnDefinition column : index.getIndexColumns()) {
+ sb2.append(glue2Inner)
+ .append(column.getOutputName().replace("\"", "\\\""));
- if (column.getSortOrder() == SortOrder.ASC)
- sb2.append(" ASC");
- else if (column.getSortOrder() == SortOrder.DESC)
- sb2.append(" DESC");
+ if (column.getSortOrder() == SortOrder.ASC)
+ sb2.append(" ASC");
+ else if (column.getSortOrder() == SortOrder.DESC)
+ sb2.append(" DESC");
- glue2Inner = ", ";
+ glue2Inner = ", ";
+ }
+
+ sb2.append("\")");
+ glue2 = ",\n";
}
- sb2.append("\")");
- glue2 = ",\n";
- }
-
- if (sb2.length() > 0) {
- out.print(", indexes = ")
- .print(scala ? "Array(" : "{");
- out.println(sb2.toString());
- out.print(scala ? ")" : "}");
+ if (sb2.length() > 0) {
+ out.print(", indexes = ")
+ .print(scala ? "Array(" : "{");
+ out.println(sb2.toString());
+ out.print(scala ? ")" : "}");
+ }
}
out.println(")");
diff --git a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.11.xml b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.11.xml
index b9954d229b..34f9512b6f 100644
--- a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.11.xml
+++ b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.11.xml
@@ -16931,6 +16931,7 @@ implements IBook {
daos: Records are a pre-requisite for DAOs. If DAOs are generated, records are generated as well
interfaces: If interfaces are generated, records will implement them
jpaAnnotations: JPA annotations are used on generated records
+ jpaVersion: Version of JPA specification is to be used to generate version-specific annotations. If it is omitted, the latest version is used by default.
Flags controlling record generation
@@ -16994,6 +16995,7 @@ public class Book implements java.io.Serializable
daos: POJOs are a pre-requisite for DAOs. If DAOs are generated, POJOs are generated as well
jpaAnnotations: JPA annotations are used on generated records
validationAnnotations: JSR-303 validation annotations are used on generated records
+ jpaVersion: Version of JPA specification is to be used to generate version-specific annotations. If it is omitted, the latest version is used by default.
Flags controlling POJO generation
diff --git a/jOOQ-meta/src/main/java/org/jooq/util/jaxb/Generate.java b/jOOQ-meta/src/main/java/org/jooq/util/jaxb/Generate.java
index 535fbd9b94..cb44464323 100644
--- a/jOOQ-meta/src/main/java/org/jooq/util/jaxb/Generate.java
+++ b/jOOQ-meta/src/main/java/org/jooq/util/jaxb/Generate.java
@@ -12,6 +12,7 @@ import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.jooq.util.jaxb.tools.StringAdapter;
@@ -78,6 +79,8 @@ public class Generate implements Serializable
protected Boolean daos = false;
@XmlElement(defaultValue = "false")
protected Boolean jpaAnnotations = false;
+ @XmlSchemaType(name = "string")
+ protected JpaVersion jpaVersion;
@XmlElement(defaultValue = "false")
protected Boolean validationAnnotations = false;
@XmlElement(defaultValue = "false")
@@ -650,6 +653,31 @@ public class Generate implements Serializable
this.jpaAnnotations = value;
}
+ /**
+ * Sets the version of JPA specification to generate version-specific annotations.
+ * If it is omitted, the latest version is used by default.
+ *
+ * @return
+ * possible object is
+ * {@link JpaVersion }
+ *
+ */
+ public JpaVersion getJpaVersion() {
+ return jpaVersion;
+ }
+
+ /**
+ * Sets the value of the jpaVersion property.
+ *
+ * @param value
+ * allowed object is
+ * {@link JpaVersion }
+ *
+ */
+ public void setJpaVersion(JpaVersion value) {
+ this.jpaVersion = value;
+ }
+
/**
* Annotate POJOs and Records with JSR-303 validation annotations
*
@@ -1242,6 +1270,11 @@ public class Generate implements Serializable
return this;
}
+ public Generate withJpaVersion(JpaVersion value) {
+ setJpaVersion(value);
+ return this;
+ }
+
public Generate withValidationAnnotations(Boolean value) {
setValidationAnnotations(value);
return this;
diff --git a/jOOQ-meta/src/main/java/org/jooq/util/jaxb/JpaVersion.java b/jOOQ-meta/src/main/java/org/jooq/util/jaxb/JpaVersion.java
new file mode 100644
index 0000000000..19c6729261
--- /dev/null
+++ b/jOOQ-meta/src/main/java/org/jooq/util/jaxb/JpaVersion.java
@@ -0,0 +1,102 @@
+/*
+ * 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.
+ *
+ * Other licenses:
+ * -----------------------------------------------------------------------------
+ * Commercial licenses for this work are available. These replace the above
+ * ASL 2.0 and offer limited warranties, support, maintenance, and commercial
+ * database integrations.
+ *
+ * For more information, please visit: http://www.jooq.org/licenses
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ */
+package org.jooq.util.jaxb;
+
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlType;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Java class for JpaVersion
+ *
+ *
The following schema fragment specifies the expected content contained within this class.
+ *
+ *
+ * <simpleType name="JpaVersion">
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ * <enumeration value="V_2_0"/>
+ * <enumeration value="V_2_1"/>
+ * <enumeration value="V_2_2"/>
+ * </restriction>
+ * </simpleType>
+ *
+ *
+ * @author Timur Shaidullin
+ */
+@XmlType(name = "JpaVersion")
+@XmlEnum
+public enum JpaVersion {
+ V_2_0(null),
+ V_2_1(V_2_0, "Index"),
+ V_2_2(V_2_1);
+
+ private final List annotations;
+
+ JpaVersion(JpaVersion previous) {
+ this(previous, new ArrayList());
+ }
+
+ JpaVersion(JpaVersion previous, String... annotations) {
+ this(previous, new ArrayList(Arrays.asList(annotations)));
+ }
+
+ JpaVersion(JpaVersion previous, List annotations) {
+ this.annotations = annotations;
+
+ if (previous != null)
+ annotations.addAll(previous.annotations);
+ }
+
+ public List getAnnotations() {
+ return annotations;
+ }
+
+ public boolean supportedIndex() {
+ return annotations.contains("Index");
+ }
+
+ public String getName() {
+ return name().substring(2).replace('_', '.');
+ }
+
+ public static JpaVersion latest() {
+ return V_2_2;
+ }
+}
diff --git a/jOOQ-meta/src/main/resources/xsd/jooq-codegen-3.11.0.xsd b/jOOQ-meta/src/main/resources/xsd/jooq-codegen-3.11.0.xsd
index 7f4f2ee0f4..2d936ff4de 100644
--- a/jOOQ-meta/src/main/resources/xsd/jooq-codegen-3.11.0.xsd
+++ b/jOOQ-meta/src/main/resources/xsd/jooq-codegen-3.11.0.xsd
@@ -908,6 +908,10 @@ jOOQ version used for source code]]>
+
+
+
+
@@ -1033,6 +1037,15 @@ This flag is ignored in the commercial Java 6 distribution of jOOQ 3.9+ ]]>
+
+
+
+
+
+
+
+
+