Available in versions: Dev (3.21) | Latest (3.20) | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11
This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.
Generated POJOs
Supported by ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
Every table and view in your database will generate a POJO implementation that looks like this:
// JPA annotations can be generated, optionally
@Entity
@Table(name = "BOOK", schema = "TEST")
public class Book implements java.io.Serializable
// An interface common to records and pojos can be generated, optionally
, IBook {
// JSR-303 annotations can be generated, optionally
@NotNull
private Integer id;
@NotNull
private Integer authorId;
@NotNull
@Size(max = 400)
private String title;
// Every column generates a getter and a setter
@Id
@Column(name = "ID", unique = true, nullable = false, precision = 7)
@Override
public Integer getId() {
return this.id;
}
@Override
public void setId(Integer id) {
this.id = id;
}
// [...]
}
<configuration>
<generator>
<generate>
<!-- Allows for turning on POJOs generation: default false -->
<pojos>true</pojos>
<!-- Optionally, limit POJOs generation to only tables matching this regular expression. -->
<pojosIncludes>.*</pojosIncludes>
<!-- Optionally, limit POJOs generation to only tables not matching this regular expression.
Excludes match before includes. -->
<pojosExcludes>SYSTEM_TABLE_.*</pojosExcludes>
</generate>
</generator>
</configuration>
See the configuration XSD, standalone code generation, and maven code generation for more details.
new org.jooq.meta.jaxb.Configuration()
.withGenerator(
new Generate()
// Allows for turning on POJOs generation: default false
.withPojos(true)
// Optionally, limit POJOs generation to only tables matching this regular expression.
.withPojosIncludes(".*")
// Optionally, limit POJOs generation to only tables not matching this regular expression.
// Excludes match before includes.
.withPojosExcludes("SYSTEM_TABLE_.*")
)
See the configuration XSD and programmatic code generation for more details.
import org.jooq.meta.jaxb.*
configuration {
generator {
generate {
// Allows for turning on POJOs generation: default false
isPojos = true
// Optionally, limit POJOs generation to only tables matching this regular expression.
pojosIncludes = ".*"
// Optionally, limit POJOs generation to only tables not matching this regular expression.
// Excludes match before includes.
pojosExcludes = "SYSTEM_TABLE_.*"
}
}
}
See the configuration XSD and gradle code generation for more details.
configuration {
generator {
generate {
// Allows for turning on POJOs generation: default false
pojos = true
// Optionally, limit POJOs generation to only tables matching this regular expression.
pojosIncludes = ".*"
// Optionally, limit POJOs generation to only tables not matching this regular expression.
// Excludes match before includes.
pojosExcludes = "SYSTEM_TABLE_.*"
}
}
}
See the configuration XSD and gradle code generation for more details.
// The jOOQ-codegen-gradle plugin has been introduced in version 3.19. // Please use the official plugin instead of the third party plugin that was recommended before.
As always, when regular expressions are used, they are regular expressions with default flags.
<configuration>
<generator>
<generate>
<!-- Allows for turning on POJOs generation: default false -->
<pojos>true</pojos>
</generate>
</generator>
</configuration>
See the configuration XSD, standalone code generation, and maven code generation for more details.
new org.jooq.meta.jaxb.Configuration()
.withGenerator(
new Generate()
// Allows for turning on POJOs generation: default false
.withPojos(true)
)
See the configuration XSD and programmatic code generation for more details.
import org.jooq.meta.jaxb.*
configuration {
generator {
generate {
// Allows for turning on POJOs generation: default false
isPojos = true
}
}
}
See the configuration XSD and gradle code generation for more details.
configuration {
generator {
generate {
// Allows for turning on POJOs generation: default false
pojos = true
}
}
}
See the configuration XSD and gradle code generation for more details.
// The jOOQ-codegen-gradle plugin has been introduced in version 3.19. // Please use the official plugin instead of the third party plugin that was recommended before.
Flags influencing generated POJOs
Additional flags from the code generation configuration influence generated POJOs:
-
daos: POJOs are a pre-requisite for DAOs. If DAOs are generated, POJOs are generated as well -
dateAsTimestamp: This influences all relevant getters and setters -
immutablePojos: Immutable POJOs have final members and no setters. All members must be passed to the constructor -
interfaces: If interfaces are generated, POJOs will implement them -
jpaAnnotations: JPA annotations are used on generated records (details here) -
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. (details here) -
pojosAsJavaRecordClasses: If you're using theJavaGenerator, this will generate POJOs as (immutable) Java 16 record types -
pojosAsScalaCaseClasses: If you're using theScalaGenerator(orScala3Generator), this will generate POJOs as (mutable or immutable) Scala case classes -
pojosAsKotlinDataClasses: If you're using theKotlinGenerator, this will generate POJOs as (mutable or immutable) kotlin data classes -
pojosToString: Whether POJOs should have a generatedtoString()implementation. -
pojosEqualsAndHashCode: Whether POJOs should have generatedequals()andhashCode()implementations. These implementations are purely value-based, just like with records, i.e. two POJOs are equal if all their attributes are equal. -
pojosEqualsAndHashCodeIncludePrimaryKeyOnly: Whether the generatedequals()andhashCode()implementations should consider primary key columns only (beware that the implementation is still purely value-based, i.e. two uninitialisednullprimary key values are then considered equal). -
pojosEqualsAndHashCodeColumnIncludeExpression: A regular expression matching qualified or unqualified column names that should be included in generatedequals()andhashCode()implementations. -
pojosEqualsAndHashCodeColumnExcludeExpression: A regular expression matching qualified or unqualified column names that should be excluded from generatedequals()andhashCode()implementations. -
unsignedTypes: This influences all relevant getters and setters -
validationAnnotations: JSR-303 validation annotations are used on generated records (details here)
Feedback
Do you have any feedback about this page? We'd love to hear it!