How to enable batch inserts in spring boot with mongo database - java

I'm having a spring boot application connected with Mongo DB now I want to enable spring batch how can I manage this withi spring data Mongo
What I saw with Spring data JPA
spring.jpa.properties.hibernate.generate_statistics=true
spring.jpa.properties.hibernate.jdbc.batch_size=1000
spring.jpa.properties.hibernate.order_inserts=true
Now how can I configure this with spring data mongo

Related

Unit testing Spring Boot Rest Controller with JPA Repositories

I have ,probably a basic question,related to unit testing a spring boot application that uses RestControllers,JPA repositories.Oracle is used in the backend.Now to unit test the JPA repositories using junit,mockito and probably DataJPA,do the tables that are present in the backend,need to be recreated in the H2 in-memory db?

JaVers in multi tenant architecture

I need to integrate my application with Javars. But, my application is multi tenant.
I am trying to integrate JaVers mongodb. I succeded in integrating JaVers. But, when the app is started, JaVers storing it's collections jv_snapshots and jv_head_id in the test database. If I delete the test db and again start the application, still the test db is automatically created and the test db would use by the JaVers.
So, How can I tell JaVers to use my own DB in a multi tenant architecture?
If you are not using Javers' Spring Boot starter:
def mongoRepository = new MongoRepository(MongoClients.create().getDatabase("my_database"))
javers = javers().registerJaversRepository(mongoRepository).build()
If you are using Javers' Spring Boot starter, Javers will automatically connect to your application's database.
And there is no notion of tenant in Javers. All you can do is to create one Javers instance per tenant or more generally one Javers instance per one db configuration.

Spring Boot does not honor spring.jpa.hibernate.ddl-auto=none property

when i run spring boot jar from my application on Linux server, always drop schema and remove all data and create the tables again my database type MySQL although i have configure spring.jpa.hibernate.ddl-auto=none in application.properties none.

How execute `schema.sql` during spring boot test without embeded datasource configuration?

There is spring boot application with h2 database which is used as primary database. Also there is a resource/schema.sql wich is loaded at startup by spring boot.
But during integration tests with #SpringBootTest spring boot does not load this schema.sql. Instead it requires to setup embeded database while there is h2 db already.
Is there a way to execute schema.sql without embeded datasource configuration? And do it only once for all tests (e.g. using #Sql for schema creation for all test is not a solution)?
Annotate your class or method with #Sql(scripts = "classpath:schema.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) where your schema.sql is on resources folder.
You need this if your tests are marked as integration tests. Spring boot will do this for you if you are running a unit test or just compiling with unit tests enabled which is the default.
Set this in your properties file and then rename schema.sql to schema-test.sql
spring.datasource.platform=test
Spring boot automatically configures the embedded database for you as long as you have the it in the classpath (h2, hsqldb or derby)

Spring Boot Enable Specific Embedded Database HSQL over Derby

I'm trying to deploy My application on weblogic server, My application has an in-memory DB and since I use HSQLDB for JUNIT, I want to keep HSQL as my in-memory DB(primarily a slight better performance over derby). Since weblogic has already derby, when I try to deploy the application, The derby is getting started rather than HSQL. On Preliminary investigation I find that Since Derby is define above HSQL in EmbeddedDatabaseConnection.java, Derby database is being started first. Is there any specific configuration, where I can explicitly embedded database type to HSQL rather than allowing spring boot to start database based on library/classes
First try I can think of is to remove Derby from class path and leave there only HSQL. Spring Boot docs:
If HSQLDB is on your classpath, and you have not manually configured
any database connection beans, then we will auto-configure an
in-memory database.
If that's not an option, you can specify
connection type for Hibernate (JPA):
An embedded database is detected by looking at the Connection type: hsqldb, h2 and derby are embedded, the rest are not.
HSQL explicitly as primary data source:
#Configuration
public class DataSourceConfig {
#Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.HSQL)
.build();
}
}
define spring.datasource.type property

Categories