Skip to content

Commit 41d0e42

Browse files
committed
readme
1 parent 9217647 commit 41d0e42

1 file changed

Lines changed: 26 additions & 19 deletions

File tree

README.md

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# TypedIds
22

3-
This library provides base classes and tooling to create typed IDs.
4-
The original goal was to allow easy and safe creation of Value Objects (VOs) backed by UUIDv7 for Hibernate ORM entities.
5-
Contributions for other ORMs or alternative JPA implementations are welcome.
3+
This library provides base classes and tooling to easily and safely create immutable typed Value Object IDs (VO-IDs) internally backed by a UUIDv7 or bigint.
4+
5+
Contributions for serialization libraries, other ORMs, alternative JPA implementations or anything else are welcome.
66

77
## Why?
88

@@ -16,21 +16,10 @@ For seamless type support in Hibernate ORM, you should pick one of the following
1616
|-------------------------------|----------------------------------------------------------------------------------------------------------------------|
1717
| 6.6, 6.5, 6.4, and 6.3 | [org.framefork:typed-ids-hibernate-63](https://central.sonatype.com/artifact/org.framefork/typed-ids-hibernate-63) |
1818
| 6.2 | [org.framefork:typed-ids-hibernate-62](https://central.sonatype.com/artifact/org.framefork/typed-ids-hibernate-62) |
19-
| 6.1 and 6.0 | TBD |
20-
| 5.6 and 5.5 | TBD |
2119

2220
Find the latest version in this project's GitHub releases or on Maven Central.
2321

24-
If you want just the plain classes, you can install only the [org.framefork:typed-ids](https://central.sonatype.com/artifact/org.framefork/typed-ids).
25-
26-
### Application-generated (random) IDs
27-
28-
This library supports several libraries for generating the IDs in the JVM but does not pull them in, instead it expects you to pick one and add it yourself.
29-
30-
* UUIDs with [`com.fasterxml.uuid:java-uuid-generator`](https://central.sonatype.com/artifact/com.fasterxml.uuid/java-uuid-generator/versions)
31-
* BigInts/longs with [`io.hypersistence:hypersistence-tsid`](https://central.sonatype.com/artifact/io.hypersistence/hypersistence-tsid/versions)
32-
33-
If you want to use a different library, the `$Generators.setFactory()` extension point should hopefully be self-explanatory.
22+
If you want just the plain base classes without ORM support, you can install just the [org.framefork:typed-ids](https://central.sonatype.com/artifact/org.framefork/typed-ids).
3423

3524
## Hibernate type mapping
3625

@@ -48,14 +37,32 @@ In some cases, that means changing the default DDL that Hibernate uses for the `
4837
The library only sets the type if there is no JDBC type for `SqlTypes.UUID` already set,
4938
which means that if you want to use something different you should be able to do so using a custom `org.hibernate.boot.model.TypeContributor`.
5039

51-
## UUID as an application-generated identifier
40+
## Database-generated identifiers
41+
42+
The library explicitly supports `AUTO`, `IDENTITY` and `SEQUENCE` strategies for generating bigint identifiers via the `@GeneratedValue` annotation for the VO-IDs.
43+
44+
This pattern is supported only for `ObjectBigIntId`.
45+
46+
## Application-generated identifiers
47+
48+
One of the primary goals of this library is to enable generated typed IDs _in application code_ - specifically in entity constructors.
5249

53-
One of the goals of this library is to enable generated typed IDs _in application code_ - specifically in entity constructors.
5450
Being able to generate identifiers in app code solves many problems around application design and architecture by getting rid of the dependency of entity on the database.
5551
The classic approach is to let the database generate the identifiers, which is perfectly fine if you prefer that, but it breaks entity state because until you persist them they're invalid and incomplete.
5652
But when you generate the ID at construction time, the entity is valid from the first moment.
53+
The only way to do this reliably is to generate random identifiers so that you don't get conflicts when persisting the entities,
54+
but using perfectly random values has its problems - see [UUID as a primary key](#uuid-as-a-primary-key) for a solution.
55+
56+
This pattern is supported for both `ObjectUuid` and `ObjectBigIntId`.
57+
58+
### Supported random application-generated identifiers generation strategies
59+
60+
This library supports several libraries for generating the IDs in the JVM but does not pull them in, instead it expects you to pick one and add it yourself.
5761

58-
The only way to do this reliably is to generate random identifiers so that you don't get conflicts when persisting the entities, but using perfectly random values has its problems...
62+
* UUIDs with [`com.fasterxml.uuid:java-uuid-generator`](https://central.sonatype.com/artifact/com.fasterxml.uuid/java-uuid-generator/versions)
63+
* BigInts/longs with [`io.hypersistence:hypersistence-tsid`](https://central.sonatype.com/artifact/io.hypersistence/hypersistence-tsid/versions)
64+
65+
If you want to use a different library, the `$Generators.setFactory()` extension point should hopefully be self-explanatory.
5966

6067
## UUID as a primary key
6168

@@ -77,7 +84,7 @@ Some additional resources:
7784
* [Choose the right primary key to save a large amount of disk I/O - Too Many Afterthoughts](https://www.toomanyafterthoughts.com/primary-key-random-sequential-performance/)
7885
* [UUID vs Bigint Battle! - Scaling Postgres 302](https://www.scalingpostgres.com/episodes/302-uuid-vs-bigint-battle/)
7986

80-
## Usage: ObjectUUID
87+
## Usage: ObjectUuid
8188

8289
The base type is designed to wrap a native UUID, and allows you to expose any utility functions you may need.
8390
The following snippet is the standard boilerplate, but you may opt to skip some of the methods, or add a few custom ones.

0 commit comments

Comments
 (0)