domingo, 31 de julio de 2022

Git Clone Repo Preserving History

 Git Clone Repo Preserving History

reference
https://docs.github.com/en/repositories/creating-and-managing-repositories/duplicating-a-repository

Repository Origin account: jalbertomr
https://github.com/jalbertomr/project-reactor-essentials-test


New Destiny Repository (To be reated in another account)  account: cuentafulana
create new Repository: cuentafulana/clonedRepoTest

1.- Create New Repository on the account where the Repository will be cloned



2.- Invite te original account to be a collaborator sending an invitation



Settings -> Collaborators





The invitation has been done, now the Account of the Source Repository has to accept the collaboration invitation.




3.- The Account of the Source Repository accepts the invitation in order to to push on the empty cloned repository




 https://github.com/cuentafulana/clonedRepoTest
 Now the source account can do push to the cloned Repository of the other account.


4.- Mirroring the repository, open git bash.

5.- Create a bare clone of the repository

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab
$ git clone --bare https://github.com/jalbertomr/project-reactor-essentials-test
Cloning into bare repository 'project-reactor-essentials-test.git'...
remote: Enumerating objects: 603, done.
remote: Counting objects: 100% (603/603), done.
remote: Compressing objects: 100% (118/118), done.
remote: Total 603 (delta 149), reused 598 (delta 144), pack-reused 0
Receiving objects: 100% (603/603), 128.95 KiB | 1.08 MiB/s, done.
Resolving deltas: 100% (149/149), done.


6.- Mirror push to the new repository

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab
$ ls
project-reactor-essentials-test.git/

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab
$ cd project-reactor-essentials-test.git

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/project-reactor-essentials-test.git (BARE:master)
$ git push --mirror https://github.com/cuentafulana/clonedRepoTest
Enumerating objects: 603, done.
Counting objects: 100% (603/603), done.
Delta compression using up to 12 threads
Compressing objects: 100% (113/113), done.
Writing objects: 100% (603/603), 128.95 KiB | 18.42 MiB/s, done.
Total 603 (delta 149), reused 603 (delta 149)
remote: Resolving deltas: 100% (149/149), done.
To https://github.com/cuentafulana/clonedRepoTest
 * [new branch]      master -> master

7.- Remove the temporary local repository you created earlier, If apply.

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab
$ rm -rf project-reactor-essentials-test.git

8.- Check the creation of the mirrored repository in the non original account


 It has the files and his commits

9.- Now modify the README.md file to indicate that this repository is a mirrored one.

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab
$ git clone https://github.com/cuentafulana/clonedRepoTest
Cloning into 'clonedRepoTest'...
remote: Enumerating objects: 603, done.
remote: Counting objects: 100% (603/603), done.
remote: Compressing objects: 100% (113/113), done.
Receiremote: Total 603 (delta 149), reused 603 (delta 149), pack-reused 0
Receiving objects: 100% (603/603), 128.95 KiB | 956.00 KiB/s, done.
Resolving deltas: 100% (149/149), done.

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab
$ dir
clonedRepoTest

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab
$ cd clonedRepoTest

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (master)
$ git branch Feature-clone

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (master)
$ git checkout Feature-clone
Switched to branch 'Feature-clone'

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (Feature-clone)
$ ls
data.txt  pom.xml  project-reactor-essentials.iml  README.md  src/  target/

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (Feature-clone)
$ nano README.md

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (Feature-clone)
$ git add README.md

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (Feature-clone)
$ git commit -m "this is a mirrored reposiotry in README.md"
[Feature-clone 438d19b] this is a mirrored reposiotry in README.md
 1 file changed, 1 insertion(+), 1 deletion(-)

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (Feature-clone)
$ git status
On branch Feature-clone
nothing to commit, working tree clean

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (Feature-clone)
$ git remote
origin

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (Feature-clone)
$ git push
fatal: The current branch Feature-clone has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin Feature-clone


bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (Feature-clone)
$ git push --set-upstream origin Feature-clone
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 343 bytes | 343.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
remote:
remote: Create a pull request for 'Feature-clone' on GitHub by visiting:
remote:      https://github.com/cuentafulana/clonedRepoTest/pull/new/Feature-clone
remote:
To https://github.com/cuentafulana/clonedRepoTest
 * [new branch]      Feature-clone -> Feature-clone
Branch 'Feature-clone' set up to track remote branch 'Feature-clone' from 'origin'.

10.- Now Cloned Mirrored Repository has the new branch feature-clone (2 branches)



 
11.- Let´s protect the master branch in order that a pull Request is required before merging







12.- Let´s check the difference between branches

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (master)
$ git diff master Feature-clone
diff --git a/README.md b/README.md
index a5a4453..1e4b134 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Project Reactor Essentials Tests
+# Project Reactor Essentials Tests (this is a mirrored Repository)
 A Walk through Project Reactor with test


13.- Let´s merge the branch Feature-clone into master

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (master)
$ git merge Feature-clone
Updating d801901..438d19b
Fast-forward
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


14.- Now we can se the change on master - READMEmd file

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (master)
$ head README.md
# Project Reactor Essentials Tests (this is a mirrored Repository)
A Walk through Project Reactor with test


- Dependencies
- setup Tests
- Mono.just, subscribe(), log()
- subscribe( Consumer, errorConsumer)
- subscribe( Consumer, errorConsumer, CompleteConsumer)
- subscribe( Consumer, errorConsumer, CompleteConsumer, subscriptionConsumer)

15.- Now let´s push the master branch to the repository

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (master)
$ git push -u origin master
Total 0 (delta 0), reused 0 (delta 0)
remote: error: GH006: Protected branch update failed for refs/heads/master.
remote: error: At least 1 approving review is required by reviewers with write access.
To https://github.com/cuentafulana/clonedRepoTest
 ! [remote rejected] master -> master (protected branch hook declined)
error: failed to push some refs to 'https://github.com/cuentafulana/clonedRepoTest'

We protect the master branch, so we need a pull Request and approval, so the push is not completed.

16.- Create a Pull Request master <-- Feature-clone




On the another account appears the pull request requiring aproval




Commented and closed pull request


ReOpen and Add your review


Review Changes -- Approve


Submit review


Now we can do the push

bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (master)
$ git push -u origin master
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/cuentafulana/clonedRepoTest
   d801901..438d19b  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.




In the Account of the cloned Repository the change on the master branch of the README.md file is visible


Other simple operations


$git status
$git branch -a
#create new branch
$git branch new-branch-name
#change environment to the new branch
$git checkout new-branch-name
 
Git checkout Remote Branch
#create a new branch
$git branch new-branch-name
#change environment to the new branch
$git checkout new-branch-name
#create a change
$touch change.txt
#commit the change
$git add .
$git commit -m "add a new change"
#push to a new branch
$git push --set-upstream origin new-branch

Git Checkout new branch

#fetch all remote branches
$git fetch origin
#list all branches
$git branch -a
#Pull Changes to a Remote Branch
$git checkout -b remote-branch origin/remote-branch

with the remote branch active, do another change
$touch anotherChange.txt
$git add .
$git commit -m "another change"
$git push

git push origin/remote-branch commando was not necessary

eot






martes, 21 de junio de 2022

Spring Data Jpa Entity RelationShip Mappings @OneToMany Unidirection (No middle table)

Spring Data Jpa Entity RelationShip Mappings @OneToMany Unidirection (No middle table)



Java Entities

PurchaseOrder Entity


@Entity
@Data
@NoArgsConstructor
@NamedQuery(name="PurchaseOrder.findById_named", query = " FROM PurchaseOrder p JOIN FETCH p.items i WHERE p.id = :id")
@Table(name = "purchase_order", schema = "public")
public class PurchaseOrder {
@Id
@GeneratedValue(strategy = GenerationType.AUTO,generator = "public.purchase_order_seq")
private Long id;
private String name;
@OneToMany( cascade = CascadeType.ALL, targetEntity = Item.class) //default targetEntity can be omitted
@JoinColumn(name = "purchase_order_id_fk", // default is "item.items_id" And Avoids the creation of extra Table
referencedColumnName = "id") // default could be omitted
private List<Item> items = new ArrayList<>();


Item Entity


@Entity
@Data
@NoArgsConstructor
@Table(name = "item", schema = "public")
public class Item {
@Id
@GeneratedValue(strategy = GenerationType.AUTO,generator = "public.item_seq")
private Long id;
private String name;


Hibernate creates automatically the tables the next way

Hibernate: 
    
    create table public.item (
       id int8 not null,
        name varchar(255),
        purchase_order_id_fk int8,
        primary key (id)
    )
Hibernate: 
    
    create table public.purchase_order (
       id int8 not null,
        name varchar(255),
        primary key (id)
    )
Hibernate: 
    
    alter table if exists public.item 
       add constraint FK1ohvucgh093bf3fnpbhhitv47 
       foreign key (purchase_order_id_fk
       references public.purchase_order

Test the behaviour


eot

Spring Data Jpa Entity RelationShip Mappings @OneToOne Bidirection (With middle table)

Spring Data Jpa Entity RelationShip Mappings @OneToOne Bidirection (With middle table)




The relation between two entities of bidirectional kind using a table in between allows at database level but at data jpa not allow have the many to one relations that can be possible at database level.

Java Entities

Person Entity

@Entity
@NoArgsConstructor
@Table(name = "person", schema = "public")
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator="public.person_seq")
private Long id;
private String name;
@OneToOne(cascade = CascadeType.ALL) // fetch default EAGER
@JoinTable( name = "person_personpicture", schema = "public",
joinColumns = { @JoinColumn(name = "person_id")}, // could be omitted
inverseJoinColumns = { @JoinColumn(name = "personpicture_id")}) // could be omitted
private PersonPicture personPicture;

public void addPicture(PersonPicture personPicture){
this.setPersonPicture(personPicture);
personPicture.setPerson(this);
}

public void removePicture(){
this.personPicture.setPerson(null);
this.personPicture = null;
}
PersonPicture Entity

@Entity
@NoArgsConstructor
@Table(name = "person_picture", schema = "public")
public class PersonPicture {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "public.person_picture_seq")
private Long id;
private String name;

@OneToOne(mappedBy = "personPicture", cascade = CascadeType.ALL)
private Person person;

public void addPerson(Person person){
person.setPersonPicture(this);
this.setPerson(person);
}

public void removePerson(){
this.person.setPersonPicture(null);
this.person = null;
}


Hibernate creates automatically the tables the next way

Hibernate: 
    
    create table public.person (
       id int8 not null,
        name varchar(255),
        primary key (id)
    )
Hibernate: 
    
    create table public.person_personpicture (
       personpicture_id int8,
        person_id int8 not null,
        primary key (person_id)
    )
Hibernate: 
    
    create table public.person_picture (
       id int8 not null,
        name varchar(255),
        primary key (id)
    )
Hibernate: 
    
    alter table if exists public.person_personpicture 
       add constraint FK9nfe8f1mtx9xjvxp5mnqrvhla 
       foreign key (personpicture_id) 
       references public.person_picture
Hibernate: 
    
    alter table if exists public.person_personpicture 
       add constraint FKencuxcn11kv9j2vycvuth8575 
       foreign key (person_id) 
       references public.person

Test the behaviour

@Transactional
public void createPersonAndPicture(){
Person person1 = new Person("Jose Alberto");
PersonPicture personPicture = new PersonPicture("picture of Person ...");
person1.addPicture(personPicture);
personRepository.save(person1);
}

At the output the queries generated by hibernate on this test.

Saving Person insert also Person_Picture

Hibernate: 
    select
        nextval ('public.person_seq')
Hibernate: 
    select
        nextval ('public.person_picture_seq')
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.PersonPicture
        */ insert 
        into
            public.person_picture
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person_personpicture
            (personpicture_id, person_id) 
        values
            (?, ?)


@Transactional
public void createPersonAndTryMorePictures(){
Person person1 = new Person("Jose Alberto");
PersonPicture personPicture = new PersonPicture("picture of Person ...");
PersonPicture personPicture2 = new PersonPicture("picture of Jose Alberto 2");
person1.addPicture(personPicture);
personRepository.save(person1);
person1.addPicture(personPicture2);
personRepository.save(person1);
}

The queries

Hibernate: 
    select
        nextval ('public.person_seq')
Hibernate: 
    select
        nextval ('public.person_picture_seq')
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.PersonPicture
        */ insert 
        into
            public.person_picture
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person_personpicture
            (personpicture_id, person_id) 
        values
            (?, ?)
Hibernate: 
    /* load com.bext.onetoonebidirectable.entity.Person */ select
        person0_.id as id1_0_2_,
        person0_.name as name2_0_2_,
        person0_1_.personpicture_id as personpi1_1_2_,
        personpict1_.id as id1_2_0_,
        personpict1_.name as name2_2_0_,
        personpict1_1_.person_id as person_i0_1_0_,
        person2_.id as id1_0_1_,
        person2_.name as name2_0_1_,
        person2_1_.personpicture_id as personpi1_1_1_ 
    from
        public.person person0_ 
    left outer join
        public.person_personpicture person0_1_ 
            on person0_.id=person0_1_.person_id 
    left outer join
        public.person_picture personpict1_ 
            on person0_1_.personpicture_id=personpict1_.id 
    left outer join
        public.person_personpicture personpict1_1_ 
            on personpict1_.id=personpict1_1_.personpicture_id 
    left outer join
        public.person person2_ 
            on personpict1_1_.person_id=person2_.id 
    left outer join
        public.person_personpicture person2_1_ 
            on person2_.id=person2_1_.person_id 
    where
        person0_.id=?
Hibernate: 
    select
        nextval ('public.person_picture_seq')
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.PersonPicture
        */ insert 
        into
            public.person_picture
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* update
        com.bext.onetoonebidirectable.entity.Person */ update
            public.person_personpicture 
        set
            personpicture_id=? 
        where
            person_id=?



@Transactional
public void createPictureAndPerson(){
PersonPicture personPicture = new PersonPicture("picture of Person :)");
Person _person = new Person("Jose Alberto");
personPicture.addPerson( _person);
personPictureRepository.save(personPicture);
}

At the output the queries generated by hibernate on this test.

Saving PersonPicture require previous save Person in order to insert also Person.

Hibernate: 
    select
        nextval ('public.person_picture_seq')
Hibernate: 
    select
        nextval ('public.person_seq')
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.PersonPicture
        */ insert 
        into
            public.person_picture
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person_personpicture
            (personpicture_id, person_id) 
        values
            (?, ?)


@Transactional
public void createPersonAddPicture_checkBidirection(){
createPersonAndPicture();

Person _person = personRepository.findById(1L).get();
log.info("_person: {}", _person);

PersonPicture _personPicture = _person.getPersonPicture();
log.info("_person.getPersonPicture() is Proxy: {}", (_personPicture instanceof HibernateProxy) ? "YES" : "NO"); //YES
log.info("_person.getPersonPicture() in Initialized {}", Hibernate.isInitialized( _personPicture)); //true

log.info("_PersonPicture1: {}", _personPicture);
}
The output create the queries

Hibernate: 
    select
        nextval ('public.person_seq')
Hibernate: 
    select
        nextval ('public.person_picture_seq')
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.PersonPicture
        */ insert 
        into
            public.person_picture
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person_personpicture
            (personpicture_id, person_id) 
        values
            (?, ?)
Hibernate: 
    select
        person0_.id as id1_0_0_,
        person0_.name as name2_0_0_,
        person0_1_.personpicture_id as personpi1_1_0_,
        personpict1_.id as id1_2_1_,
        personpict1_.name as name2_2_1_,
        personpict1_1_.person_id as person_i0_1_1_,
        person2_.id as id1_0_2_,
        person2_.name as name2_0_2_,
        person2_1_.personpicture_id as personpi1_1_2_ 
    from
        public.person person0_ 
    left outer join
        public.person_personpicture person0_1_ 
            on person0_.id=person0_1_.person_id 
    left outer join
        public.person_picture personpict1_ 
            on person0_1_.personpicture_id=personpict1_.id 
    left outer join
        public.person_personpicture personpict1_1_ 
            on personpict1_.id=personpict1_1_.personpicture_id 
    left outer join
        public.person person2_ 
            on personpict1_1_.person_id=person2_.id 
    left outer join
        public.person_personpicture person2_1_ 
            on person2_.id=person2_1_.person_id 
    where
        person0_.id=?
2022-06-21 18:49:27.945  INFO 33636 --- [           main] .o.SpringdatajpaentitymappingApplication : _person: Person{id=1, name='Jose Alberto', picture.name=picture of Person ...}
2022-06-21 18:49:27.948  INFO 33636 --- [           main] .o.SpringdatajpaentitymappingApplication : _person.getPersonPicture() is Proxy: NO
2022-06-21 18:49:27.949  INFO 33636 --- [           main] .o.SpringdatajpaentitymappingApplication : _person.getPersonPicture() in Initialized true
2022-06-21 18:49:27.949  INFO 33636 --- [           main] .o.SpringdatajpaentitymappingApplication : _PersonPicture1: PersonPicture{id=1, name='picture of Person ...', person.name=Jose Alberto}


@Transactional
public void createPictureAddPerson_checkBidirection(){
createPictureAndPerson();

PersonPicture _personPicture = personPictureRepository.findById(1L).get();
log.info("_personPicture", _personPicture);

Person _person = _personPicture.getPerson();
log.info("_personPicture.getPerson() is Proxy: {}", (_person instanceof HibernateProxy) ? "YES" : "NO");
log.info("_personPicture.getPerson() is Initialized {}", Hibernate.isInitialized( _person));

log.info("_person: {}", _person);
}
The queries generated

Hibernate: 
    select
        nextval ('public.person_picture_seq')
Hibernate: 
    select
        nextval ('public.person_seq')
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.PersonPicture
        */ insert 
        into
            public.person_picture
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person_personpicture
            (personpicture_id, person_id) 
        values
            (?, ?)
Hibernate: 
    select
        personpict0_.id as id1_2_0_,
        personpict0_.name as name2_2_0_,
        personpict0_1_.person_id as person_i0_1_0_,
        person1_.id as id1_0_1_,
        person1_.name as name2_0_1_,
        person1_1_.personpicture_id as personpi1_1_1_,
        personpict2_.id as id1_2_2_,
        personpict2_.name as name2_2_2_,
        personpict2_1_.person_id as person_i0_1_2_ 
    from
        public.person_picture personpict0_ 
    left outer join
        public.person_personpicture personpict0_1_ 
            on personpict0_.id=personpict0_1_.personpicture_id 
    left outer join
        public.person person1_ 
            on personpict0_1_.person_id=person1_.id 
    left outer join
        public.person_personpicture person1_1_ 
            on person1_.id=person1_1_.person_id 
    left outer join
        public.person_picture personpict2_ 
            on person1_1_.personpicture_id=personpict2_.id 
    left outer join
        public.person_personpicture personpict2_1_ 
            on personpict2_.id=personpict2_1_.personpicture_id 
    where
        personpict0_.id=?
2022-06-21 18:53:32.626  INFO 43788 --- [           main] .o.SpringdatajpaentitymappingApplication : _personPicture
2022-06-21 18:53:32.626  INFO 43788 --- [           main] .o.SpringdatajpaentitymappingApplication : _personPicture.getPerson() is Proxy: NO
2022-06-21 18:53:32.626  INFO 43788 --- [           main] .o.SpringdatajpaentitymappingApplication : _personPicture.getPerson() is Initialized true
2022-06-21 18:53:32.626  INFO 43788 --- [           main] .o.SpringdatajpaentitymappingApplication : _person: Person{id=1, name='Jose Alberto', picture.name=picture of Person :)}


@Transactional
public void getPerson_checkPicture(){
createPersonAndPicture();

Person _person = personRepository.findById(1L).get();

PersonPicture personPicture = _person.getPersonPicture();

log.info("Person: {}", _person);
log.info("PersonPicture: {}", personPicture);
}

The queries generated

Hibernate: 
    select
        nextval ('public.person_seq')
Hibernate: 
    select
        nextval ('public.person_picture_seq')
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.PersonPicture
        */ insert 
        into
            public.person_picture
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person_personpicture
            (personpicture_id, person_id) 
        values
            (?, ?)
Hibernate: 
    select
        person0_.id as id1_0_0_,
        person0_.name as name2_0_0_,
        person0_1_.personpicture_id as personpi1_1_0_,
        personpict1_.id as id1_2_1_,
        personpict1_.name as name2_2_1_,
        personpict1_1_.person_id as person_i0_1_1_,
        person2_.id as id1_0_2_,
        person2_.name as name2_0_2_,
        person2_1_.personpicture_id as personpi1_1_2_ 
    from
        public.person person0_ 
    left outer join
        public.person_personpicture person0_1_ 
            on person0_.id=person0_1_.person_id 
    left outer join
        public.person_picture personpict1_ 
            on person0_1_.personpicture_id=personpict1_.id 
    left outer join
        public.person_personpicture personpict1_1_ 
            on personpict1_.id=personpict1_1_.personpicture_id 
    left outer join
        public.person person2_ 
            on personpict1_1_.person_id=person2_.id 
    left outer join
        public.person_personpicture person2_1_ 
            on person2_.id=person2_1_.person_id 
    where
        person0_.id=?
2022-06-21 18:56:43.657  INFO 43696 --- [           main] .o.SpringdatajpaentitymappingApplication : Person: Person{id=1, name='Jose Alberto', picture.name=picture of Person ...}
2022-06-21 18:56:43.661  INFO 43696 --- [           main] .o.SpringdatajpaentitymappingApplication : PersonPicture: PersonPicture{id=1, name='picture of Person ...', person.name=Jose Alberto}


@Transactional
public void getPicture_checkPerson(){
createPictureAndPerson();

PersonPicture _personPicture = personPictureRepository.findById(1L).get();

Person _person = _personPicture.getPerson();

log.info("PersonPicture: {}", _personPicture);
log.info("Person: {}", _person);
}

The queries generated

Hibernate: 
    select
        nextval ('public.person_picture_seq')
Hibernate: 
    select
        nextval ('public.person_seq')
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.PersonPicture
        */ insert 
        into
            public.person_picture
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person_personpicture
            (personpicture_id, person_id) 
        values
            (?, ?)
Hibernate: 
    select
        personpict0_.id as id1_2_0_,
        personpict0_.name as name2_2_0_,
        personpict0_1_.person_id as person_i0_1_0_,
        person1_.id as id1_0_1_,
        person1_.name as name2_0_1_,
        person1_1_.personpicture_id as personpi1_1_1_,
        personpict2_.id as id1_2_2_,
        personpict2_.name as name2_2_2_,
        personpict2_1_.person_id as person_i0_1_2_ 
    from
        public.person_picture personpict0_ 
    left outer join
        public.person_personpicture personpict0_1_ 
            on personpict0_.id=personpict0_1_.personpicture_id 
    left outer join
        public.person person1_ 
            on personpict0_1_.person_id=person1_.id 
    left outer join
        public.person_personpicture person1_1_ 
            on person1_.id=person1_1_.person_id 
    left outer join
        public.person_picture personpict2_ 
            on person1_1_.personpicture_id=personpict2_.id 
    left outer join
        public.person_personpicture personpict2_1_ 
            on personpict2_.id=personpict2_1_.personpicture_id 
    where
        personpict0_.id=?
2022-06-21 18:58:27.889  INFO 40816 --- [           main] .o.SpringdatajpaentitymappingApplication : PersonPicture: PersonPicture{id=1, name='picture of Person :)', person.name=Jose Alberto}
2022-06-21 18:58:27.893  INFO 40816 --- [           main] .o.SpringdatajpaentitymappingApplication : Person: Person{id=1, name='Jose Alberto', picture.name=picture of Person :)}


@Transactional
public void deletePerson_checkPersonPictureAlsoDeleted(){
createPersonAndPicture();

personRepository.deleteById(1L);

log.info("person exist: {}",personRepository.existsById(1L)); // false
log.info("personPicture exist: {}", personPictureRepository.existsById(1L)); // false
}

The queries executed

Hibernate: 
    select
        nextval ('public.person_seq')
Hibernate: 
    select
        nextval ('public.person_picture_seq')
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.PersonPicture
        */ insert 
        into
            public.person_picture
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person_personpicture
            (personpicture_id, person_id) 
        values
            (?, ?)
Hibernate: 
    select
        person0_.id as id1_0_0_,
        person0_.name as name2_0_0_,
        person0_1_.personpicture_id as personpi1_1_0_,
        personpict1_.id as id1_2_1_,
        personpict1_.name as name2_2_1_,
        personpict1_1_.person_id as person_i0_1_1_,
        person2_.id as id1_0_2_,
        person2_.name as name2_0_2_,
        person2_1_.personpicture_id as personpi1_1_2_ 
    from
        public.person person0_ 
    left outer join
        public.person_personpicture person0_1_ 
            on person0_.id=person0_1_.person_id 
    left outer join
        public.person_picture personpict1_ 
            on person0_1_.personpicture_id=personpict1_.id 
    left outer join
        public.person_personpicture personpict1_1_ 
            on personpict1_.id=personpict1_1_.personpicture_id 
    left outer join
        public.person person2_ 
            on personpict1_1_.person_id=person2_.id 
    left outer join
        public.person_personpicture person2_1_ 
            on person2_.id=person2_1_.person_id 
    where
        person0_.id=?
Hibernate: 
    /* delete com.bext.onetoonebidirectable.entity.Person */ delete 
        from
            public.person_personpicture 
        where
            person_id=?
Hibernate: 
    /* delete com.bext.onetoonebidirectable.entity.Person */ delete 
        from
            public.person 
        where
            id=?
Hibernate: 
    /* delete com.bext.onetoonebidirectable.entity.PersonPicture */ delete 
        from
            public.person_picture 
        where
            id=?
Hibernate: 
    /* select
        count(*) 
    from
        Person x 
    WHERE
        x.id = :id */ select
            count(*) as col_0_0_ 
        from
            public.person person0_ 
        where
            person0_.id=?
2022-06-21 19:03:46.476  INFO 58620 --- [           main] .o.SpringdatajpaentitymappingApplication : person exist: false
Hibernate: 
    /* select
        count(*) 
    from
        PersonPicture x 
    WHERE
        x.id = :id */ select
            count(*) as col_0_0_ 
        from
            public.person_picture personpict0_ 
        where
            personpict0_.id=?
2022-06-21 19:03:46.478  INFO 58620 --- [           main] .o.SpringdatajpaentitymappingApplication : personPicture exist: false


@Transactional
public void deletePersonPicture_checkPersonAlsoDeleted(){
createPictureAndPerson();
List<PersonPicture> all = personPictureRepository.findAll();
all.forEach( pp -> log.info("finadAll personPictures: {}",pp) );

//personRepository.deleteById(1L); // This delete Person and PersonPicture
personPictureRepository.deleteById(1L); // This don´t Delete PersonPicture

log.info("personPicture exist: {}", personPictureRepository.existsById(1L)); // true
log.info("person: {}", personRepository.existsById(1L)); // true
}
The queries executed

Hibernate: 
    select
        nextval ('public.person_picture_seq')
Hibernate: 
    select
        nextval ('public.person_seq')
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.PersonPicture
        */ insert 
        into
            public.person_picture
            (name, id) 
        values
            (?, ?)
Hibernate: 
    /* insert com.bext.onetoonebidirectable.entity.Person
        */ insert 
        into
            public.person_personpicture
            (personpicture_id, person_id) 
        values
            (?, ?)
Hibernate: 
    /* select
        generatedAlias0 
    from
        PersonPicture as generatedAlias0 */ select
            personpict0_.id as id1_2_,
            personpict0_.name as name2_2_,
            personpict0_1_.person_id as person_i0_1_ 
        from
            public.person_picture personpict0_ 
        left outer join
            public.person_personpicture personpict0_1_ 
                on personpict0_.id=personpict0_1_.personpicture_id
Hibernate: 
    select
        person0_.id as id1_0_0_,
        person0_.name as name2_0_0_,
        person0_1_.personpicture_id as personpi1_1_0_,
        personpict1_.id as id1_2_1_,
        personpict1_.name as name2_2_1_,
        personpict1_1_.person_id as person_i0_1_1_,
        person2_.id as id1_0_2_,
        person2_.name as name2_0_2_,
        person2_1_.personpicture_id as personpi1_1_2_ 
    from
        public.person person0_ 
    left outer join
        public.person_personpicture person0_1_ 
            on person0_.id=person0_1_.person_id 
    left outer join
        public.person_picture personpict1_ 
            on person0_1_.personpicture_id=personpict1_.id 
    left outer join
        public.person_personpicture personpict1_1_ 
            on personpict1_.id=personpict1_1_.personpicture_id 
    left outer join
        public.person person2_ 
            on personpict1_1_.person_id=person2_.id 
    left outer join
        public.person_personpicture person2_1_ 
            on person2_.id=person2_1_.person_id 
    where
        person0_.id=?
2022-06-21 19:06:21.852  INFO 55232 --- [           main] .o.SpringdatajpaentitymappingApplication : finadAll personPictures: PersonPicture{id=1, name='picture of Person :)', person.name=Jose Alberto}
Hibernate: 
    select
        personpict0_.id as id1_2_0_,
        personpict0_.name as name2_2_0_,
        personpict0_1_.person_id as person_i0_1_0_,
        person1_.id as id1_0_1_,
        person1_.name as name2_0_1_,
        person1_1_.personpicture_id as personpi1_1_1_,
        personpict2_.id as id1_2_2_,
        personpict2_.name as name2_2_2_,
        personpict2_1_.person_id as person_i0_1_2_ 
    from
        public.person_picture personpict0_ 
    left outer join
        public.person_personpicture personpict0_1_ 
            on personpict0_.id=personpict0_1_.personpicture_id 
    left outer join
        public.person person1_ 
            on personpict0_1_.person_id=person1_.id 
    left outer join
        public.person_personpicture person1_1_ 
            on person1_.id=person1_1_.person_id 
    left outer join
        public.person_picture personpict2_ 
            on person1_1_.personpicture_id=personpict2_.id 
    left outer join
        public.person_personpicture personpict2_1_ 
            on personpict2_.id=personpict2_1_.personpicture_id 
    where
        personpict0_.id=?
Hibernate: 
    /* delete com.bext.onetoonebidirectable.entity.Person */ delete 
        from
            public.person_personpicture 
        where
            person_id=?
Hibernate: 
    /* delete com.bext.onetoonebidirectable.entity.PersonPicture */ delete 
        from
            public.person_picture 
        where
            id=?
Hibernate: 
    /* delete com.bext.onetoonebidirectable.entity.Person */ delete 
        from
            public.person_personpicture 
        where
            person_id=?
Hibernate: 
    /* delete com.bext.onetoonebidirectable.entity.Person */ delete 
        from
            public.person 
        where
            id=?
Hibernate: 
    /* select
        count(*) 
    from
        PersonPicture x 
    WHERE
        x.id = :id */ select
            count(*) as col_0_0_ 
        from
            public.person_picture personpict0_ 
        where
            personpict0_.id=?
2022-06-21 19:06:21.874  INFO 55232 --- [           main] .o.SpringdatajpaentitymappingApplication : personPicture exist: false
Hibernate: 
    /* select
        count(*) 
    from
        Person x 
    WHERE
        x.id = :id */ select
            count(*) as col_0_0_ 
        from
            public.person person0_ 
        where
            person0_.id=?
2022-06-21 19:06:21.877  INFO 55232 --- [           main] .o.SpringdatajpaentitymappingApplication : person: false



eot