Mapping Guide
The best resource for learning how to map JDO entities is the DataNucleus website. Take a look at:
In addition, we have a couple of articles on specific mapping use cases:
Custom Value Types
The framework provides a number of custom value types.
Some of these are wrappers around a single value (eg AsciiDoc
or Password
) while others map onto multiple values (eg Blob
).
This section shows how to map each (and can be adapted for your own custom types or @Embedded
values).
Mapping AsciiDoc
-
In the domain entity, map
AsciiDoc
type using@Column(jdbcType = "CLOB")
:MyEntity.javapublic class MyEntity ... { @Column(allowsNull = "false", jdbcType = "CLOB") @Property @Getter @Setter private AsciiDoc documentation; }
-
in the webapp module, register the JDO specific converter by:
-
adding a dependency to this module:
pom.xml<dependency> <groupId>org.apache.isis.valuetypes</groupId> <artifactId>isis-valuetypes-asciidoc-persistence-jdo</artifactId> </dependency>
-
and adding reference the corresponding module in the
AppManifest
:AppManifest.java@Configuration @Import({ ... IsisModuleValAsciidocPersistenceJdo.java ... }) public class AppManifest { }
-
Mapping Markdown
The Markdown value type is used for documentation written using markdown:
-
In the domain entity, map
Markdown
type using@Column(jdbcType = "CLOB")
:MyEntity.javapublic class MyEntity ... { @Column(allowsNull = "false", jdbcType = "CLOB") @Property @Getter @Setter private Markdown documentation; }
-
in the webapp module, register the JDO specific converter by:
-
adding a dependency to this module:
pom.xml<dependency> <groupId>org.apache.isis.valuetypes</groupId> <artifactId>isis-valuetypes-markdown-persistence-jdo</artifactId> </dependency>
-
and adding reference the corresponding module in the
AppManifest
:AppManifest.java@Configuration @Import({ ... IsisModuleValMarkdownPersistenceJdo.java ... }) public class AppManifest { }
-
Mapping Blobs and Clobs
The JDO ObjectStore integration of DataNucleus ORM can automatically persist Blob and Clob values into multiple columns, corresponding to their constituent parts.
Blobs
To map a Blob, use:
public class MyEntity ... {
@Persistent(defaultFetchGroup="false", columns = {
@Column(name = "pdf_name"), (1)
@Column(name = "pdf_mimetype"), (2)
@Column(name = "pdf_bytes") (3)
})
@Getter @Setter
private Blob pdf;
}
1 | string, maps to a varchar in the database |
2 | string, maps to a varchar in the database |
3 | byte array, maps to a Blob or varbinary in the database |
Clobs
To map a Clob, use:
public class MyEntity ... {
@Persistent(defaultFetchGroup="false", columns = {
@Column(name = "xml_name"), (1)
@Column(name = "xml_mimetype"), (2)
@Column(name = "xml_chars" (3)
, jdbcType = "CLOB"
)
})
@Getter @Setter
private Clob xml;
}
1 | string, maps to a varchar in the database |
2 | string, maps to a varchar in the database |
3 | char array, maps to a Clob or varchar in the database |