Precondition
To quickly preview Jimmer's main features, we need to provide several entities here as the basic assumption of all discussions in this section.
Status of Entities
In Jimmer applications, the only thing that matters is the unified global ORM entity model.
The global entity model is finalized with the database design, irrelevant to specific query/modification business logics' requirements for interaction formats, and relatively stable.
As for what kind of DTO types each query/modification business needs to interact with, it is completely unimportant.
-
Either no DTO is needed at all, e.g. Quick View/Query Arbitrary Shape/Exposing Features/Return Entities Directly.
-
Or DTO types can be quickly generated through Object/DTO Conversion/DTO Language, making DTO extremely cheap.
Only the relatively stable entity model is important. So Jimmer is good at handling changing requirements.
UML Relationships Between Entities
Here we list three entity types: BookStore
, Book
, Author
and TreeNode
, as the basic assumptions for all discussions in the current section.
Entity Type Definitions
BookStore
- Java
- Kotlin
@Entity
public interface BookStore {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
long id();
String name();
@Nullable
String website();
@OneToMany(mappedBy = "store")
List<Book> books();
}
@Entity
interface BookStore {
@Id
@@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long
val name: String
val website: String?
@OneToMany(mappedBy = "store")
val books: List<Book>
}
Book
- Java
- Kotlin
@Entity
public interface Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
long id();
@Key
String name();
@Key
int edition();
BigDecimal price();
@Nullable
@ManyToOne
BookStore store();
@ManyToMany
List<Author> authors();
}
@Entity
interface Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long
@Key
val name: String
@Key
val edition: Int
val price: BigDecimal
@ManyToOne
val store: BookStore?
@ManyToMany
val authors: List<Author>
}
Author
- Java
- Kotlin
@Entity
public interface Author {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
UUID id();
@Key
String firstName();
@Key
String lastName();
Gender gender();
@ManyToMany(mappedBy = "authors")
List<Book> books();
}
@Entity
interface Author {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long
@Key
val firstName String
@Key
val lastName: String
val gender: Gender
@ManyToMany(mappedBy = "authors")
val books: List<Book>
}
Where Gender is a very simple enum type
- Java
- Kotlin
public enum Gender { MALE, FEMALE }
enum class Gender { MALE, FEMALE }