NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

----- JPA/Hibernate:
Was ist JPA? Und wie hibernate verbunden mit es?

EN: The Java Persistence API (JPA), in 2019 renamed to Jakarta Persistence,
is a Java application programming interface specification that describes the management of relational data in applications using Java Platform,
Standard Edition and Java Platform, Enterprise Edition/Jakarta EE.

EN: After Java EE was open sourced by Oracle and gave the rights to the Eclipse Foundation they were legally required to change the name
from Java as Oracle has the rights over the Java brand. The name Jakarta was chosen by the community.

LINKS:
https://blogs.oracle.com/theaquarium/post/opening-up-java-ee-an-update
https://blogs.oracle.com/theaquarium/post/the-road-to-jakarta-ee
https://www.eclipse.org/community/eclipse_newsletter/2018/may/noturningback.php

------Migration from javax.persistance.* to jakarta.persistance.*

DE: OK, Früher es war Java Persistence API und jetzt es ist Jakarta Persistence API, was das für uns bedeutet.
Java Persistence API ist im package jjavax.persistence-api:2.2 und Jackarta Persistence ist im jakarta.persistence-api:3.0.0.
Im wirklichkeit jakarta.persistence-api:3.0 hat keine Änderung, aßer package umbenennung.
Es ist gemacht so, damit JPA Implementirungen und Projekten sehr einfach könnten migriren von Java Persistence API auf Jakarta Persitence API.
Migrations von Große Porjekten ist noch im progrress. Zum Beispiel spring-boot-starter-data-jpa hat die reference auf jakarta.persistence-api:3.0 nur im Version 2.6.0-SNAPSHOT.
Deshalb bei uns im Projekt verwenden wir auch alle JPA annatationen noch von package javax.persistence.
Ich werde doch referenzieren auf die Jakarta Dokumentation, weil dort man aktuelle information kriegen wird: jetzt aber nur Packages anderen namen haben.


implementation("javax.persistence:javax.persistence-api:2.2")
implementation("jakarta.persistence:jakarta.persistence-api:2.2.3") - hat trinnen javax.persistence.* packages
implementation("jakarta.persistence:jakarta.persistence-api:3.0.0")


spring-boot-starter-data-jpa:2.5.5 => jakarta.persistence-api:2.2.3
spring-boot-starter-data-jpa:2.6.0-SNAPSHOT => jakarta.persistence-api:3.0.0


LINKS:
https://www.youtube.com/watch?v=11mB8NM8g8c
https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api/2.2
https://mvnrepository.com/artifact/jakarta.persistence/jakarta.persistence-api
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa


------ JPA Implementirungen
DE:Es gibt auf dem Mark 3 populäre JPA Implementirungen. Das sind: Hibernate, EclipseLink und Apache OpenJPA.
Wir verwendedn Hibernate und das sind am popülärste JPA Implementierung.

EN: JPA permits the developer to work directly with objects rather than with SQL statements. The JPA implementation is typically called persistence provider.
The mapping between Java objects and database tables is defined via persistence metadata. The JPA provider will use the persistence metadata information to perform the correct database operations.
JPA metadata is typically defined via annotations in the Java class.


------ Entity:
EN: A class which should be persisted in a database it must be annotated with javax.persistence.Entity. Such a class is called Entity. JPA uses a database table for every entity. Persisted instances of the class will be represented as one row in the table.
All entity classes must define a primary key, must have a non-arg constructor and or not allowed to be final. Keys can be a single field or a combination of fields.
JPA allows to auto-generate the primary key in the database via the @GeneratedValue annotation.
By default, the table name corresponds to the class name. You can change this with the addition to the annotation @Table(name="NEWTABLENAME").


---- Persistence of fields
EN: The fields of the Entity will be saved in the database. JPA can use either your instance variables (fields) or the corresponding getters and setters to access the fields. You are not allowed to mix both methods. If you want to use the setter and getter methods the Java class must follow the Java Bean naming conventions. JPA persists per default all fields of an Entity, if fields should not be saved they must be marked with @Transient.
By default each field is mapped to a column with the name of the field. You can change the default name via @Column (name="newColumnName").


----- Relationship Mapping
EN: JPA allows to define relationships between classes, e.g. it can be defined that a class is part of another class (containment). Classes can have one to one, one to many, many to one, and many to many relationships with other classes.
A relationship can be bidirectional or unidirectional, e.g. in a bidirectional relationship both classes store a reference to each other while in an unidirectional case only one class has a reference to the other class. Within a bidirectional relationship you need to specify the owning side of this relationship in the other class with the attribute "mappedBy", e.g. @ManyToMany(mappedBy="attributeOfTheOwningClass".
Relationship annotations:
@OneToOne
@OneToMany
@ManyToOne
@ManyToMany

---- Constraint Annotations
asdasdasd






------ Entity Manager
EN: The entity manager javax.persistence.EntityManager provides the operations from and to the database, e.g. find objects, persists them, remove objects from the database, etc.
In a JavaEE application the entity manager is automatically inserted in the web application. Outside JavaEE you need to manage the entity manager yourself.
Entities which are managed by an Entity Manager will automatically propagate these changes to the database (if this happens within a commit statement). If the Entity Manager is closed (via close()) then the managed entities are in a detached state. If synchronize them again with the database a Entity Manager provides the merge() method.
The persistence context describes all Entities of one Entity manager.

If we didn't use Spring Data JPA, we'd have to write more boilerplate code to persist entities to the database...

------ Repository Pattern
EN: One of the main purpuse of repository pattern to provide a centralized handling of the domain objects. For each Entity or Entity Group, you should create one repository class and the only channel you should use to update the database should be the repositories.


CONF: The Repository pattern is a well-documented way of working with a data source. In the book Patterns of Enterprise Application Architecture, Martin Fowler describes a repository as follows:
A repository performs the tasks of an intermediary between the domain model layers and data mapping, acting in a similar way to a set of domain objects in memory. Client objects declaratively build queries and send them to the repositories for answers. Conceptually, a repository encapsulates a set of objects stored in the database and operations that can be performed on them, providing a way that is closer to the persistence layer. Repositories, also, support the purpose of separating, clearly and in one direction, the dependency between the work domain and the data allocation or mapping.

Link:
- Image: https://docs.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/infrastructure-persistence-layer-design
- https://deviq.com/design-patterns/repository-pattern
- https://medium.com/@pererikbergman/repository-design-pattern-e28c0f3e4a30


--- Spring Data JPA
EN: By default, Spring Data JPA repositories are default Spring beans. They are singleton scoped and eagerly initialized. During startup, they already interact with the JPA EntityManager for verification and metadata analysis purposes.


Links: https://docs.spring.io/spring-data/jpa/docs/2.5.5/reference/html/#jpa.java-config


---- Core Concept
EN:
--- https://docs.spring.io/spring-data/jpa/docs/2.5.5/reference/html/#repositories.core-concepts


---- Using @Query




     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.