Spring-boot JPA multiple data-sources is not updating or creating tables

Spring-boot JPA multiple data-sources is not updating or creating tables

I am facing a problem with JPA with spring-boot with multiple data-sources. It is something I have always managed to do. But this time I cannot understand why is not working?

I am facing a problem with JPA with spring-boot with multiple data-sources. It is something I have always managed to do. But this time I cannot understand why is not working?

After gradle build or bootRun no table is being created or updated. No compile or run time errors at startup. I am losing my mind.

You can find my code attached.

P2BDatabaseConfig.groovy

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
        entityManagerFactoryRef = "p2bEntityManagerFactory",
        transactionManagerRef = "p2bTransactionManager",
        basePackages = {"it.project.sol.sharpapi.repo.p2b"}
)
public class P2BDatabaseConfig {

@Bean(name = "p2bDataSource")
@ConfigurationProperties(prefix = "spring.p2b")
@Primary
public DataSource dataSource() {
    return DataSourceBuilder.create().build();
}

@PersistenceContext(unitName = "p2bPU")
@Bean(name = "p2bEntityManagerFactory")
@Primary
public LocalContainerEntityManagerFactoryBean p2bEntityManagerFactory(EntityManagerFactoryBuilder builder,
                                                                      @Qualifier("p2bDataSource") DataSource dataSource) {
    return builder.dataSource(dataSource).packages("it.project.sol.sharpapi.entity.p2b").build();
}

@Bean(name = "p2bTransactionManager")
@Primary
public PlatformTransactionManager p2bTransactionManager(
        @Qualifier("p2bEntityManagerFactory") EntityManagerFactory p2bEntityManagerFactory) {
    return new JpaTransactionManager(p2bEntityManagerFactory);
}

}

SharpDatabaseConfig.groovy

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
        entityManagerFactoryRef = "sharpEntityManagerFactory",
        transactionManagerRef = "sharpTransactionManager",
        basePackages = {"it.project.sol.sharpapi.repo.sharp"}
)
public class SharpDatabaseConfig {

@Bean(name = "sharpDataSource")
@ConfigurationProperties(prefix = "spring.sharp")
public DataSource dataSource() {
    return DataSourceBuilder.create().build();
}

@PersistenceContext(unitName = "sharpPU")
@Bean(name = "sharpEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean sharpEntityManagerFactory(EntityManagerFactoryBuilder builder,
                                                                      @Qualifier("sharpDataSource") DataSource dataSource) {
    return builder.dataSource(dataSource).packages("it.project.sol.sharpapi.entity.sharp").build();
}

@Bean(name = "sharpTransactionManager")
public PlatformTransactionManager sharpTransactionManager(
        @Qualifier("sharpEntityManagerFactory") EntityManagerFactory sharpEntityManagerFactory) {
    return new JpaTransactionManager(sharpEntityManagerFactory);
}

}

application.yml

spring:
  profiles:
    active: Developement

jpa: show-sql: true database-platform: org.hibernate.dialect.MySQL5InnoDBDialect hibernate: ddl-auto: update naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy dialect: org.hibernate.dialect.MySQL5Dialect

p2b: url: jdbc:mysql://localhost:3306/p2bv2?autoReconnect=true username: xxxx password: xxxx! testWhileIdle: true maxActive: 5 validationQuery: SELECT 1 driver-class-name: com.mysql.jdbc.Driver

sharp: url: jdbc:mysql://localhost:3306/sharp?autoReconnect=true username: xxxx password: xxxx! testWhileIdle: true maxActive: 5 validationQuery: SELECT 1 driver-class-name: com.mysql.jdbc.Driver

P2BDevice.groovy

@Entity(name = "P2BDevice")
@Table(name = "device")
class P2BDevice implements Serializable{

@Id
@GeneratedValue
Long id

@Column(name = "version")
Long version

@Column(name = "date_created")
Date dateCreated

@Column(name = "deleted")
int deleted

@Column(name = "description")
String description

...

}

User.groovy

@Entity(name = "User")
@Table(name = "caccapupu")
class User implements Serializable{

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id

@Column(name = "version")
Long version

@Column(name = "username")
String username

@Column(name = "password")
Long password

@Column(name = "date_created")
Date dateCreated

@Column(name = "status")
int status

...

}

I can assure you, repositories are correct and even the packages position of my classes.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Java Spring - Limiting Query Result with Spring Data JPA

Java Spring - Limiting Query Result with Spring Data JPA

Build a Basic App with Spring Boot and JPA using PostgreSQL

Build a Basic App with Spring Boot and JPA using PostgreSQL. Install PostgreSQL for JPA Persistence. Create a PostgreSQL Database for Your JPA Entities. Build a Spring Boot Resource Server. Add a Domain Class with Spring Data and JPA. Implement a CRUD Repository with Spring Data JPA.

Spring Boot With Spring Data JPA

Welcome to the Spring Boot with Spring Data JPA tutorial! In this tutorial, we are going to see how Spring Data JPA provides complete abstraction over the DAO layer. We don’t need to write the implementation for the DAO layer anymore; Spring Data auto-generates the implementation DAO implementations.