Giriş
1. Yapılabilecek İşler
1.1 Database initialization
1. Initialize a database using JPA
2. Initialize a database using Spring JDBC
1.2 JPA
1.2.1 Metadata'dan Veri tabanı Oluşturma Script'i Yaratma
Önce şöyle yaparız. Böylece uygulama her başladığında schema yaratılır. Eğer bu alanı true yapmazsak mevcut dosyalar varsa, bu dosyalar baştan yaratılmazlar yani overwrite edilmezler.
Önce şöyle yaparız. Böylece uygulama her başladığında schema yaratılır. Eğer bu alanı true yapmazsak mevcut dosyalar varsa, bu dosyalar baştan yaratılmazlar yani overwrite edilmezler.
spring.jpa.generate-ddl=truespring.jpa.properties.javax.persistence.schema-generation.create-source=metadataspring.jpa.properties.javax.persistence.schema-generation.scripts.action=createspring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=create.sql
1.2.2 Metadata'dan Veri tabanını Otomatik Oluşturma
SpringBoot JPA Database Initialization yazısına taşıdım
2. Initialize a database using Spring JDBC
schema.sql, data.sql gibi özel dosyalar varsa bu dosyaları çalıştırır. SpringBoot Database Initialization Script Dosyaları yazısına taşıdım
2. Alanlar
Bazı alanlara bakalım
database Alanı
Bu satıra normalde gerek yok. Otomatik olarak veri tabanı tipi bulunur. Şöyle yaparız.
Açıklaması şöyle.
Açıklaması şöyle.
show-sql Alanı
SQL Loglama Ayaraları yazısına taşıdım
Bu satıra normalde gerek yok. Otomatik olarak veri tabanı tipi bulunur. Şöyle yaparız.
spring.jpa.database=MYSQLAçıklaması şöyle.
database-platform is actually unnecessary. Spring Data/Hibernate can autodetect the platform. However, without this property, if you run the app without having started your Postgres server, what you’ll get is a rather unhelpful error about not having added this config property instead of being told to start your server. This happens because Hibernate cannot autodetect the database platform, so complains about that before complaining about there not actually being a running server.Şöyle yaparız.
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialectAçıklaması şöyle.
Spring Boot by default enables the OpenEntityManagerInViewInterceptor which enables the open entitymanager in view pattern. This in turn leads you to a single EntityManager per request.
Açıklaması şöyle. Yani true ise @Transactional anotasyonuna bakmadan, EntityManager controller içinde de etkindir. Dolayısıyla OneToMany gibi lazy ilişkilerde, child tarafe view içinde de erişilebilir.
true : Maintains persistence context until the response or view is rendered to the clientfalse : After the Transaction, the persistence context is also closed
Örnek - true
Şöyle yaparız.spring.jpa.open-in-view=truebulkUpsert(@RequestBody Orders orders){
  for(Order order:orders.getOrders()){
       saveOrUpdateOrder(order);
  }
}@Transactional
saveOrUpdateOrder(Order order){
   //do processing and call dao methods to save/update
}show-sql Alanı
SQL Loglama Ayaraları yazısına taşıdım
 
Hiç yorum yok:
Yorum Gönder