Sean Robertson

Sean Robertson

1547866579

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?

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.

#java #spring #jpa

What is GEEK

Buddha Community

Zara Bryant

1548142439

Try to explicitly set JPA properties

    LocalContainerEntityManagerFactoryBean em = 
builder.dataSource(dataSource).packages("it.project.sol.sharpapi.entity.sharp").build();
            HashMap<String, Object> properties = new HashMap<>();
            properties.put("hibernate.hbm2ddl.auto", "update");
            properties.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
            em.setJpaPropertyMap(properties);

Siphiwe  Nair

Siphiwe Nair

1620466520

Your Data Architecture: Simple Best Practices for Your Data Strategy

If you accumulate data on which you base your decision-making as an organization, you should probably think about your data architecture and possible best practices.

If you accumulate data on which you base your decision-making as an organization, you most probably need to think about your data architecture and consider possible best practices. Gaining a competitive edge, remaining customer-centric to the greatest extent possible, and streamlining processes to get on-the-button outcomes can all be traced back to an organization’s capacity to build a future-ready data architecture.

In what follows, we offer a short overview of the overarching capabilities of data architecture. These include user-centricity, elasticity, robustness, and the capacity to ensure the seamless flow of data at all times. Added to these are automation enablement, plus security and data governance considerations. These points from our checklist for what we perceive to be an anticipatory analytics ecosystem.

#big data #data science #big data analytics #data analysis #data architecture #data transformation #data platform #data strategy #cloud data platform #data acquisition

Sean Robertson

Sean Robertson

1547866579

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?

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.

#java #spring #jpa

Gerhard  Brink

Gerhard Brink

1620629020

Getting Started With Data Lakes

Frameworks for Efficient Enterprise Analytics

The opportunities big data offers also come with very real challenges that many organizations are facing today. Often, it’s finding the most cost-effective, scalable way to store and process boundless volumes of data in multiple formats that come from a growing number of sources. Then organizations need the analytical capabilities and flexibility to turn this data into insights that can meet their specific business objectives.

This Refcard dives into how a data lake helps tackle these challenges at both ends — from its enhanced architecture that’s designed for efficient data ingestion, storage, and management to its advanced analytics functionality and performance flexibility. You’ll also explore key benefits and common use cases.

Introduction

As technology continues to evolve with new data sources, such as IoT sensors and social media churning out large volumes of data, there has never been a better time to discuss the possibilities and challenges of managing such data for varying analytical insights. In this Refcard, we dig deep into how data lakes solve the problem of storing and processing enormous amounts of data. While doing so, we also explore the benefits of data lakes, their use cases, and how they differ from data warehouses (DWHs).


This is a preview of the Getting Started With Data Lakes Refcard. To read the entire Refcard, please download the PDF from the link above.

#big data #data analytics #data analysis #business analytics #data warehouse #data storage #data lake #data lake architecture #data lake governance #data lake management

Were  Joyce

Were Joyce

1620736200

Introduction to Spring Boot and JDBCTemplate: Refactoring to SpringData JPA

Introduction to Spring Boot and JDBCTemplate: Refactoring to SpringData JPA.

Refactoring is the process of modifying a software system without changing its desirable behavior. It was necessary to have an application integrated with the relational database using the Spring JDBC Template in the first parts. The Spring JDBC Template is a powerful tool that facilitates productivity. However, there is a way to simplify the code even further with Spring Data JPA. The purpose of this post is to refactor the project to use Spring Data JPA.

Spring Data JPA, part of the larger Spring Data family, makes it easy to implement JPA-based repositories easily. This module deals with enhanced support for JPA-based data access layers. It makes it easier to build Spring-powered applications that use data access technologies.

A safe code refactoring requires the use of tests to ensure that the compartment is not changed. The use of tests, fortunately, is adopted as a minimum standard, including several methodologies such as TDD that preach the creation of tests at the beginning of the development process.

#java #tutorial #spring #spring data #java tutorial #spring tutorial #spring data jpa

Sigrid  Farrell

Sigrid Farrell

1624442580

Spring Data Projections

A quick introduction to Spring data Projections!

Spring Data supports custom queries in Repositories where developers just need to follow a set way of writing repository methods for the functionality they are looking for. Just defining the method in the interface does the job, for most types of searches at least. Developers pick the functionality and the fields to search by, create the method and pass in the required parameters and the method does what it is supposed to do.

This is pretty straightforward and easy. But say you don’t (for whatever reason) want the whole entity or object returned as a part of your query. Say you only want a subset of fields from the original entity: Spring data projections to the rescue!

Spring supports different types of projections: interface-based, class-based, and dynamic projections. For the sake of this article, I am going to stick to interface-based projections. The Spring Data documentation has excellent information on the other types!

Before we jump in, I am using the following versions of tools and languages:

On that note, let us talk about how to use spring data projections step by step, using books as the resource we want to manage:

Step 1: Defining the Entity

Step 2: Defining the Repository

Step 3: Using the Repository to Save and Retrieve data

Step 4: Introducing Projections!

#jpa #spring-data #spring-boot #programming #kotlin #spring data projections