Skip to content

Commit 4f72533

Browse files
committed
HHH-9998 - Continue documentation TLC - mapping basic-types
1 parent 84987f4 commit 4f72533

31 files changed

+911
-61
lines changed

documentation/src/main/docbook/manual/en-US/chapters/domain/DomainModel.xml

Lines changed: 2 additions & 2 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -34,8 +34,8 @@
34
<para>
34
<para>
35
This chapter will describe the characteristics of a persistable domain model. However, it will not discuss
35
This chapter will describe the characteristics of a persistable domain model. However, it will not discuss
36
defining the mapping for the domain model. That is a massive topic in its own right and is the subject of an
36
defining the mapping for the domain model. That is a massive topic in its own right and is the subject of an
37-
entire dedicated manual. See the <citetitle>Hibernate - Domain Model Mapping</citetitle> documentation
37+
entire dedicated manual. See the <citetitle>Hibernate Domain Model Mapping Guide</citetitle> from the
38-
from the <link xlink:href="http://hibernate.org/documentation">documentation site</link>.
38+
<link xlink:href="http://hibernate.org/documentation">documentation site</link>.
39
</para>
39
</para>
40

40

41
<section xml:id="domainmodel-pojo">
41
<section xml:id="domainmodel-pojo">

documentation/src/main/docbook/mapping/en-US/Hibernate_Mapping.xml

Lines changed: 13 additions & 4 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -48,17 +48,26 @@
48
<xi:include href="chapters/basic/Basic_Types.xml" />
48
<xi:include href="chapters/basic/Basic_Types.xml" />
49
<xi:include href="chapters/composition/Composition.xml" />
49
<xi:include href="chapters/composition/Composition.xml" />
50
<xi:include href="chapters/collection/Collection.xml" />
50
<xi:include href="chapters/collection/Collection.xml" />
51+
<xi:include href="chapters/entity/Entity.xml" />
52+
<xi:include href="chapters/id/Identifiers.xml" />
53+
<xi:include href="chapters/natural_id/Natural_Id.xml" />
51

54

52
<!--
55
<!--
53-
<xi:include href="chapters/entity/Entity.xml" />
54-
<xi:include href="chapters/id/Identifiers.xml" />
55
<xi:include href="chapters/association/Associations.xml" />
56
<xi:include href="chapters/association/Associations.xml" />
56-
<xi:include href="chapters/natural_id/Natural_Id.xml" />
57+
<xi:include href="chapters/secondary/Secondary_Tables.xml" />
58+
59+
<xi:include href="chapters/constraints/Database_Constraints.xml" /> pk, fk, index, check, unique
60+
<xi:include href="chapters/auxiliary/Auxiliary_DB_Objects.xml" />
57
61
58-
<xi:include href="chapters/generation/Generated_attributes.xml" />
59
<xi:include href="chapters/access/Attribute_Access.xml" />
62
<xi:include href="chapters/access/Attribute_Access.xml" />
60
<xi:include href="chapters/overrides/Mapping_Overrides.xml" /> AttributeOverrides/AssociationOverrides
63
<xi:include href="chapters/overrides/Mapping_Overrides.xml" /> AttributeOverrides/AssociationOverrides
64+
65+
<xi:include href="chapters/generation/Generated_attributes.xml" />
66+
67+
columns, formulas, read/write-fragments
68+
61
<xi:include href="chapters/naming/Naming_Strategies.xml" />
69
<xi:include href="chapters/naming/Naming_Strategies.xml" />
70+
<xi:include href="chapters/quoting/SQL_Identifier_Quoting.xml" />
62
-->
71
-->
63

72

64
<!-- appendices? -->
73
<!-- appendices? -->

documentation/src/main/docbook/mapping/en-US/chapters/basic/Basic_Types.xml

Lines changed: 432 additions & 25 deletions
Large diffs are not rendered by default.
Lines changed: 5 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
create table step(
2+
...
3+
instruction BLOB not null,
4+
...
5+
)
Lines changed: 8 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@Entity
2+
public class Step {
3+
...
4+
@Lob
5+
@Basic
6+
public Blob instructions;
7+
...
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@Entity
2+
public class Step {
3+
...
4+
@Lob
5+
@Basic
6+
public byte[] instructions;
7+
...
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
create table product(
2+
...
3+
description CLOB not null,
4+
...
5+
)
Lines changed: 8 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@Entity
2+
public class Product {
3+
...
4+
@Lob
5+
@Basic
6+
public Clob description;
7+
...
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@Entity
2+
public class Product {
3+
...
4+
@Lob
5+
@Basic
6+
public String description;
7+
...
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@Entity
2+
public class Product {
3+
...
4+
@Lob
5+
@Basic
6+
public char[] description;
7+
...
8+
}
Lines changed: 53 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
@Entity
2+
public class Person {
3+
...
4+
@Basic
5+
@Convert( converter=GenderConverter.class )
6+
public Gender gender;
7+
}
8+
9+
public enum Gender {
10+
MALE( 'M' ),
11+
FEMALE( 'F' );
12+
13+
private final char code;
14+
15+
private Gender(char code) {
16+
this.code = code;
17+
}
18+
19+
public char getCode() {
20+
return code;
21+
}
22+
23+
public static Gender fromCode(char code) {
24+
if ( code == 'M' || code == 'm' ) {
25+
return MALE;
26+
}
27+
if ( code == 'F' || code == 'f' ) {
28+
return FEMALE;
29+
}
30+
throw ...
31+
}
32+
}
33+
34+
@Converter
35+
public class GenderConverter
36+
implements AttributeConverter<Character,Gender> {
37+
38+
public Character convertToDatabaseColumn(Gender value) {
39+
if ( value == null ) {
40+
return null;
41+
}
42+
43+
return value.getCode();
44+
}
45+
46+
public Gender convertToEntityAttribute(Character value) {
47+
if ( value == null ) {
48+
return null;
49+
}
50+
51+
return Gender.fromCode( value );
52+
}
53+
}
Lines changed: 82 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import org.hibernate.type.descriptor.java.CharacterTypeDescriptor;
2+
3+
@Entity
4+
public class Person {
5+
...
6+
@Basic
7+
@Type( type = GenderType.class )
8+
public Gender gender;
9+
}
10+
11+
public enum Gender {
12+
MALE( 'M' ),
13+
FEMALE( 'F' );
14+
15+
private final char code;
16+
17+
private Gender(char code) {
18+
this.code = code;
19+
}
20+
21+
public char getCode() {
22+
return code;
23+
}
24+
25+
public static Gender fromCode(char code) {
26+
if ( code == 'M' || code == 'm' ) {
27+
return MALE;
28+
}
29+
if ( code == 'F' || code == 'f' ) {
30+
return FEMALE;
31+
}
32+
throw ...
33+
}
34+
}
35+
36+
@Converter
37+
public class GenderType
38+
extends AbstractSingleColumnStandardBasicType<Gender> {
39+
40+
public static final GenderType INSTANCE = new GenderType();
41+
42+
private GenderType() {
43+
super(
44+
CharTypeDescriptor.INSTANCE,
45+
GenderJavaTypeDescriptor.INSTANCE
46+
);
47+
}
48+
49+
public String getName() {
50+
return "gender";
51+
}
52+
53+
@Override
54+
protected boolean registerUnderJavaType() {
55+
return true;
56+
}
57+
}
58+
59+
public static class GenderJavaTypeDescriptor
60+
extends AbstractTypeDescriptor<Gender> {
61+
public static final GenderJavaTypeDescriptor INSTANCE = new GenderJavaTypeDescriptor();
62+
63+
public String toString(Gender value) {
64+
return value == null ? null : value.name();
65+
}
66+
67+
public Gender fromString(String string) {
68+
return string == null ? null : Gender.valueOf( string );
69+
}
70+
71+
public <X> X unwrap(Gender value, Class<X> type, WrapperOptions options) {
72+
return CharacterTypeDescriptor.INSTANCE.unwrap(
73+
value == null ? null : value.getCode(),
74+
type,
75+
options
76+
);
77+
}
78+
79+
public <X> Gender wrap(X value, WrapperOptions options) {
80+
return CharacterTypeDescriptor.INSTANCE.wrap( value, options );
81+
}
82+
}
Lines changed: 11 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@Entity
2+
public class Person {
3+
...
4+
@Enumerated
5+
public Gender gender;
6+
7+
public static enum Gender {
8+
MALE,
9+
FEMALE
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@Entity
2+
public class Person {
3+
...
4+
@Enumerated(STRING)
5+
public Gender gender;
6+
7+
public static enum Gender {
8+
MALE,
9+
FEMALE
10+
}
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@Entity
2+
public class Product {
3+
@Id
4+
@Basic
5+
private Integer id;
6+
@Basic
7+
private String sku;
8+
@Basic
9+
private String name;
10+
@Basic
11+
@Column( name = "NOTES" )
12+
private String description;
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@Entity
2+
public class Product {
3+
...
4+
@Lob
5+
@Basic
6+
@Nationalized
7+
public NClob description;
8+
// Clob also works, because NClob
9+
// extends Clob. The db type is
10+
// still NCLOB either way and
11+
// handled as such
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@Entity
2+
public class Product {
3+
...
4+
@Lob
5+
@Basic
6+
@Nationalized
7+
public String description;
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@Entity
2+
public class Product {
3+
...
4+
@Basic
5+
@Nationalized
6+
public String description;
7+
...
8+
}

documentation/src/main/docbook/mapping/en-US/chapters/collection/Collection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -73,7 +73,7 @@
73
<title>Bags</title>
73
<title>Bags</title>
74
<para>
74
<para>
75
<!-- todo : discuss mapping bags -->
75
<!-- todo : discuss mapping bags -->
76-
todo : discuss mapping bags
76+
todo : discuss mapping bags and idbags
77
</para>
77
</para>
78
</section>
78
</section>
79

79

Lines changed: 22 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Hibernate, Relational Persistence for Idiomatic Java
4+
~
5+
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
6+
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
7+
-->
8+
<chapter xml:id="entity"
9+
version="5.0"
10+
xml:lang="en"
11+
xmlns="http://docbook.org/ns/docbook"
12+
>
13+
<title>Entity</title>
14+
<para>
15+
* POJO, etc discussion from manual/en-US/chapters/domain/DomainModel.xml
16+
* dynamic models (hbm.xml)
17+
* Map mode
18+
* proxy solutions (hibernate-core/src/test/java/org/hibernate/test/dynamicentity/tuplizer2)
19+
* inheritance
20+
* optimistic locking
21+
</para>
22+
</chapter>

0 commit comments

Comments
 (0)