Browse Source

conectando a MariaDB

master
Juanjo 1 year ago
parent
commit
ac3897ff8b
2 changed files with 26 additions and 10 deletions
  1. +17
    -3
      src/main/java/es/fp/edu/conecta2/BDConfig.java
  2. +9
    -7
      src/main/resources/application.properties

+ 17
- 3
src/main/java/es/fp/edu/conecta2/BDConfig.java View File

@ -7,9 +7,12 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;
@Configuration
@EnableTransactionManagement
@ -32,12 +35,23 @@ public class BDConfig {
return dataSource;
}
@Bean(name="userEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(){
@Bean(name = "userEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
// TODO: 27/01/2023
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(userDatasource());
em.setPackagesToScan("es.fp.edu.conecta2.modelo.user");
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
Map<String,Object> properties = new HashMap<>();
properties.put("hibernate.hbm2ddl.auto", env.getProperty("persistente.jpa.hibernate.ddl-auto"));
properties.put("hibernate.show-sql", env.getProperty("persistente.jpa.show-sql"));
properties.put("hibernate.dialect", env.getProperty("persistente.jpa.properties.hibernate.dialect"));
em.setJpaPropertyMap(properties);
return em;
}
}

+ 9
- 7
src/main/resources/application.properties View File

@ -1,3 +1,5 @@
server.port=9000
spring.thymeleaf.cache=false
server.compression.enabled=true
@ -9,15 +11,15 @@ spring.data.rest.base-path=/api
persistente.datasource.url=jdbc:mariadb://localhost:3306/bolsa
persistente.datasource.username=bolsa
persistente.datasource.password=1234
persistente.datasource.driver-class-name=org.mariadb.jdbc.Driver
persistente.datasource.testWhileIdle=true
persistente.datasource.validationQuery=SELECT 1
persistente.datasource.driverClassName=org.mariadb.jdbc.Driver
persistente.jpa.show-sql=true
#JPA
# none, validate, update, create-drop
persistente.jpa.hibernate.ddl-auto=validate
persistente.jpa.show-sql=true
persistente.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDB103Dialect
persistente.jpa.hibernate.ddl-auto=update
persistente.datasource.testWhileIdle=true
persistente.datasource.validationQuery=SELECT 1
persistente.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect
persistente.jpa.database-platform=org.hibernate.dialect.MariaDBDialect
#persistente.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl
#persistente.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy


Loading…
Cancel
Save