Skip to content

Commit ab6da6e

Browse files
schaudergregturn
authored andcommitted
DATAJDBC-156 - Describe available mappings in README.
Includes the major limitations and their rational.
1 parent 06b15da commit ab6da6e

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

README.adoc

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@ The primary goal of the http://projects.spring.io/spring-data[Spring Data] proje
44

55
== This is NOT an ORM
66

7-
Spring Data JDBC does not try to be an ORM. It is not a competitor to JPA. Instead it is more of a construction kit for your personal ORM that you can define the way you like or need it.
7+
Spring Data JDBC does not try to be an ORM. It is not a competitor to JPA.
8+
Instead it is more of a construction kit for your personal ORM that you can define the way you like or need it.
89

9-
This means that it does rather little out of the box. But it offers plenty of places where you can put your own logic, or integrate it with the technology of your choice for generating SQL statements.
10+
This means that it does rather little out of the box.
11+
But it offers plenty of places where you can put your own logic, or integrate it with the technology of your choice for generating SQL statements.
12+
13+
== The Aggregate Root
14+
15+
Spring Data repositories are inspired by the repository as described in the book Domain Driven Design by Eric Evans.
16+
One consequence of this is that you should have a repository per Aggregate Root.
17+
Aggregate Root is another concept from the same book and describes an entity which controls the lifecycle of other entities which together are an Aggregate.
18+
An Aggregate is a subset of your model which is consistent between method calls to your Aggregate Root.
19+
20+
Spring Data JDBC tries its best to encourage modelling your domain along these ideas.
1021

1122
== Maven Coordinates
1223

@@ -57,6 +68,49 @@ public void someMethod() {
5768
}
5869
----
5970

71+
==== Supported types in your entity
72+
73+
Properties of the following types are currently supported:
74+
75+
* all primitive types and their boxed types (`int`, `float`, `Integer`, `Float` ...)
76+
77+
* enums get mapped to their name.
78+
79+
* `String`
80+
81+
* `java.util.Date`, `java.time.LocalDate`, `java.time.LocalDateTime`, `java.time.LocalTime`
82+
83+
and anything your database driver accepts.
84+
85+
* references to other entities, which will be considered a one-to-one relationship.
86+
The table of the referenced entity is expected to have an additional column named like the table of the referencing entity.
87+
This name can be changed by implementing `NamingStrategy.getReverseColumnName(JdbcPersistentProperty property)` according to your preferences.
88+
89+
* `Set<some entity>` will be considered a one-to-many relationship.
90+
The table of the referenced entity is expected to have an additional column named like the table of the referencing entity.
91+
This name can be changed by implementing `NamingStrategy.getReverseColumnName(JdbcPersistentProperty property)` according to your preferences.
92+
93+
* `Map<simple type, some entity>` will be considered a qualified one to many relationship.
94+
The table of the referenced entity is expected to have two additional columns: One named like the table of the referencing entity for the foreign key and one with the same name and an additional `_key` suffix for the map key.
95+
This name can be changed by implementing `NamingStrategy.getReverseColumnName(JdbcPersistentProperty property)` and `NamingStrategy.getKeyColumn(JdbcPersistentProperty property)` according to your preferences.
96+
97+
The handling of referenced entities is very limited.
98+
Part of this is because this project is still before it's first release.
99+
100+
But another reason is the idea of <<The Aggregate Root,Aggregate Roots>> as described above.
101+
If you reference another entity that entity is by definition part of your Aggregate.
102+
So if you remove the reference it will get deleted.
103+
This also means references will be 1-1 or 1-n, but not n-1 or n-m.
104+
105+
If your having n-1 or n-m references you are probably dealing with two separate Aggregates.
106+
References between those should be encode as simple ids, which should map just fine with Spring Data JDBC.
107+
108+
Also the mapping we offer is very limited for a third reason which already was mentioned at the very beginning of the document: This is not an ORM.
109+
We will offer ways to plug in your own SQL in various ways.
110+
But the default mapping itself will stay limited.
111+
If you want highly customizable mappings which support almost everything one can imagine you will probably be much happier with (Spring Data) JPA.
112+
Which is a very powerful and mature technology.
113+
60114
=== Id generation
61115

62116
Spring Data JDBC uses the id to identify entities but also to determine if an entity is new or already existing in the database.
@@ -209,6 +263,8 @@ Just annotate a method with a SQL query to use this whenever the method gets cal
209263
The current MyBatis supported is rather elaborate in that it allows to execute multiple statements for a single method call.
210264
But sometimes less is more and it should be possible to annotate a method with a simple annotation to identify a SQL statement in a MyBatis mapping to be executed.
211265

266+
=== Support of lists in entities
267+
212268
== Spring Boot integration
213269

214270
There is https://github.com/schauder/spring-data-jdbc-boot-starter[preliminary Spring Boot integration].

0 commit comments

Comments
 (0)