-
Notifications
You must be signed in to change notification settings - Fork 3
Home
Welcome to the cifojava2022-6 wiki!
Name | Type | Description | Link |
---|---|---|---|
universalPlanes | Server | Basic Spring Boot Project | Done |
JpaInherenceLibrary | Server-Inherence | Inhrence with JPA and UML @Entity |
Done |
JpaInherenceLibrary1 | Server-Inherence | Inhrence with JPA and UML MappedSuperClass
|
Done |
JpaInherenceLibrary2 | Server-Inherence | Inhrence with JPA and UML Single Table with Discriminator
|
Done |
JpaInherenceLibrary3 | Server-Inherence | Inhrence with JPA and UML Joined Table
|
Done |
JpaInherenceLibrary4 | Server-Inherence | Inhrence with JPA and UML Table per class
|
Done |
- there is no @Service neither @Controller
- so, they are basically back-end projects
- all work with @CrudRepository
Inheritance is a fundamental concept of POO, but Relational databases have no concept of inheritance neither NoSQL (MongoDB, DymamoDB), so persisting inheritance in a SQL and NoSQL database has its own particular way.
Because relational databases have no concept of inheritance, there is no standard way of implementing inheritance in database, so the hardest part of persisting inheritance is choosing how to represent the inheritance in the database.
JPA defines several inheritance mechanisms, mainly defined though the @Inheritance annotation or the <inheritance>
element.
There are three inheritance strategies defined from the InheritanceType enum
:
- SINGLE_TABLE
- TABLE_PER_CLASS
- JOINED
- Single table inheritance is the default with discriminator values,
- and table per class is an optional feature of the JPA spec, so not all providers may support it.
- in joined strategy each class in the hierarchy is mapped to its table.
MAPPED SUPERCLASS
- JPA also defines a mapped superclass concept defined through the @MappedSuperclass annotation or the
<mapped-superclass>
element. - A mapped superclass is not a persistent class, but allows common mappings to be defined for its subclasses.
Links: orientdb, logicbig, Java Persistence/Inheritance wikibooks and apache
JpaInherenceLibrary0
-
Base project:
- POM
- @Entity:
Book
(SuperClass),ItemBook
,RareBook
andAuhtor
-
n:m
:Book
<>Auhtor
- DataBase H2: application.properties
- Command Line Runner with methods to test
- @CrudRepository JPA 2.0, @Component (
CommandLineRunner
) and @Test (Jupiter
)
-
New Topics
-
How to code
inherence
and JPA uses SINGLE_TABLE strategy by default@Entity public class Book {} @Entity(name="BookItem") public class ItemBook extends Book { @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinTable(name = "AUTHOR_BOOK_JOIN_TABLE", joinColumns = { @JoinColumn(name = "BOOK_FK" )}, inverseJoinColumns = { @JoinColumn(name = "AUTHOR_FK" )}) private Set<Author>authors = new HashSet<Author>(); } @Entity(name="RareItem") public class RareItem extends Book {} @Entity(name="Author") @Table(name="AUTHOR_TABLE") public class Author {}
-
-
Versions
- JpaInherenceLibrary v 1.0 : without @MappedSuperClass and @Entity superclass, Single Table strategy is applied BY DEFAULT
JpaInherenceLibrary1
-
Base project:
- POM
- @Entity:
ItemBook
,RareBook
andAuhtor
- Non-@Entity:
Book
- DataBase H2: application.properties
- Command Line Runner with methods to test
- @CrudRepository JPA 2.0, @Component (
CommandLineRunner
) and @Test (Jupiter
)
-
New Topics
-
How can not we code
@MappedSuperclass
and@ManyToMany
author@MappedSuperclass public abstract class Book {} @Entity(name="BookItem") @Table(name="ITEM_BOOK_TABLE") public class ItemBook extends Book { @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinTable(name = "AUTHOR_BOOK_JOIN_TABLE", joinColumns = { @JoinColumn(name = "BOOK_FK" )}, inverseJoinColumns = { @JoinColumn(name = "AUTHOR_FK" )}) private Set<Author>authors = new HashSet<Author>(); } @Entity(name="RareItem") @Table(name="RARE_ITEM_TABLE") public class RareItem extends Book {} @Entity(name="Author") @Table(name="AUTHOR_TABLE") public class Author {}
-
With @MappedSuperclass any relationship can't be done
-
With @MappedSuperclass, one SuperClass and two SubClasses:
-
-
Versions
-
JpaInherenceLibrary1 v 1.0 : not using
author
just inherence without relatonship @ManyToMany
-
JpaInherenceLibrary1 v 1.0 : not using
JpaInherenceLibrary2
-
Base project:
- POM
- @Entity:
Book
(SuperClass),ItemBook
,RareBook
andAuhtor
-
n:m
:Book
<>Auhtor
- DataBase H2 : application.properties
- Command Line Runner with methods to test
- @CrudRepository JPA 2.0, @Component (
CommandLineRunner
) and @Test (Jupiter
)
-
New Topics
-
How to code
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="BOOK_TYPE", discriminatorType = DiscriminatorType.STRING) public class Book {} @Entity(name="BookItem") @Table(name="BOOK_ITEM_TABLE") @DiscriminatorValue(value= "ITEMBOOK") public class BookItem extends Book { @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinTable(name = "AUTHOR_BOOK_JOIN_TABLE", joinColumns = { @JoinColumn(name = "BOOK_FK" )}, inverseJoinColumns = { @JoinColumn(name = "AUTHOR_FK" )}) private Set<Author>authors = new HashSet<Author>();} @Entity(name="RareItem") @Table(name="RARE_ITEM_TABLE") @DiscriminatorValue(value= "REAREBOOK") public class RareItem extends Book {} @Entity(name="Author") @Table(name="AUTHOR_TABLE") public class Author {}
-
-
With @Inheritance and SINGLE_TABLE
version 1.0 : JpaInherenceLibrary2, SINGLE_TABLE strategy
JpaInherenceLibrary3
-
Base project:
- POM
- @Entity:
Book
(SuperClass),ItemBook
,RareBook
andAuhtor
-
n:m
:Book
<>Auhtor
- DataBase H2 : application.properties
- Command Line Runner with methods to test
- @CrudRepository JPA 2.0, @Component (
CommandLineRunner
) and @Test (Jupiter
)
-
New Topics
-
How to code
@Inheritance(strategy = InheritanceType.JOINED)
@Entity @Table(name="BOOK_TABLE") @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(name="BOOK_TYPE", discriminatorType = DiscriminatorType.STRING) public class Book {} @Entity(name="BookItem") @Table(name="BOOK_ITEM_TABLE") @PrimaryKeyJoinColumn(name = "bookItemId") @DiscriminatorValue(value= "ITEMBOOK") public class BookItem extends Book { @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinTable(name = "AUTHOR_BOOK_JOIN_TABLE", joinColumns = { @JoinColumn(name = "BOOK_FK" )}, inverseJoinColumns = { @JoinColumn(name = "AUTHOR_FK" )}) private Set<Author>authors = new HashSet<Author>();} @Entity(name="RareItem") @Table(name="RARE_ITEM_TABLE") @PrimaryKeyJoinColumn(name = "rareItemId") @DiscriminatorValue(value= "RAREBOOK") public class RareItem extends Book {} @Entity(name="Author") @Table(name="AUTHOR_TABLE") public class Author {}
-
-
With @Inheritance and JOINED
verison 1.0 : JpaInherenceLibrary3
JpaInherenceLibrary4
-
Base project:
- POM
- @Entity:
Book
(SuperClass),ItemBook
,RareBook
andAuhtor
-
n:m
:Book
<>Auhtor
- DataBase H2 : application.properties
- Command Line Runner with methods to test
- @CrudRepository JPA 2.0, @Component (
CommandLineRunner
) and @Test (Jupiter
)
-
New Topics
-
How to code
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Entity @Table(name="BOOK_TABLE") @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public class Book {} @Entity(name="BookItem") @Table(name="BOOK_ITEM_TABLE") public class BookItem extends Book { @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinTable(name = "AUTHOR_BOOK_JOIN_TABLE", joinColumns = { @JoinColumn(name = "BOOK_FK" )}, inverseJoinColumns = { @JoinColumn(name = "AUTHOR_FK" )}) private Set<Author>authors = new HashSet<Author>();} @Entity(name="RareItem") @Table(name="RARE_ITEM_TABLE") public class RareItem extends Book {} @Entity(name="Author") @Table(name="AUTHOR_TABLE") public class Author {}
-
-
With @Inheritance and TABLE_PER_CLASS
version 1.0 : JpaInherenceLibrary4
Universal Planes
-
Preliminary works:
- Create project on Spring Init
-
version 1.0 : spring boot executions