I'm writing a plain spring jdbc application using spring boot after a long time without using jpa or hibernate or any other ORM solution. I have need to print the runtime SQL for debugging purposes. I researched a little bit but could not find anything. I know in a jpa/hibernate application we can say following in application.properties
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
But not sure what is the name name of property in spring jdbc applications. Any help is appreciated.
Related
I am trying to write Spring Boot application to connect to a Teiid database, I want to use JPA layer on it. I have configured the JDBC Data Source, but since this not well-known database in Spring JPA libraries do not autodetect this source. I have manually setup "spring.jpa.*" properties too. I do have a Hibernate dialect for this database, and it is on the classpath.
So, how does one need to configure JPA layer for a not well-known database in Spring Boot? Thank you for your time.
Ramesh..
This is fairly well defined in the Spring Boot documentation.
You can set this explicitly in the application.properties file
spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
I was reading the documentation of Spring Boot and HikariCP and would like to integrate it to my SB app, but I got a little confused when it comes to Hikari and JPA.
I'm currently using Spring Data (spring-boot-starter-data-jpa) and my questions are: can I use HikariCP when using JPA? will it interfere on the way Hibernate connects to database? should I do some other configuration to make Hibernate using HikariCP? it wasn't really clear on documentations
There is no issue with using JPA and HikariCP together. Depending on which JPA implementation you want to use you can look around a bit more, but generally Hibernate and EclipseLink are supported. For example here is an example using the exact set of technologies you described:
HikariCP + JPA + spring-data
Starting from the Spring example Accessing MongoDB Data with REST (https://spring.io/guides/gs/accessing-mongodb-data-rest/) I'd like to integrate a PostgreSQL data source and link it to the MongoDB repository.By switching from MongoRepository to JpaRepository and accordingly changing the application.properties file I've been able to pass from MongoDB to PostgreSQL and viceversa, but basically having only one active data source at time.
application.properties when using MongoDB
spring.data.mongodb.port=27017
spring.data.mongodb.uri=mongodb://localhost/
spring.data.mongodb.database=myMongoDB_DB
spring.data.mongodb.repositories.enabled=true
application.properties when using PostgreSQL
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/myPostgreSQL_DB
spring.datasource.username=me
spring.datasource.password=mySuperSecretPassword
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
Is there a way to configure Spring (with an Annotation-only way) to link two data sources to the same Repository so that when I access my REST web service via HTTP both MongoDB and PostgreSQL are changed in exactly the same way?I googled around and found something about Spring cross-store support (http://docs.spring.io/spring-data/mongodb/docs/1.5.5.RELEASE/reference/html/mongo.cross.store.html) but it uses xml for the application configuration and AspectJ, is there a simpler way to accomplish this?
In this chapter you can find an answer - (Spring-boot manual - Use Spring Data JPA and Mongo repositories)
I would like to use Flyway as preferred way of database migration handling in my Spring Boot project (using current V1.2.1.RELEASE).
This is working fine so far however the integration with Spring Security using a JDBC DataSource seems to override the Flyway mechanism.
Following simple scenario:
Spring Boot 1.2.1
PostgreSQL 9.4.1
Flyway migration scripts for users, groups and authorities according to Spring Security documentation
Problem:
The Flyway migration scripts are not executed at startup as expected.
Maybe cause: It seems that Flyway is only executed at startup if the using Spring Boot project is also using JPA at least. Since Spring Security is based on plain JDBC, I've tried to temporary use the JDBC based database initialization scheme as described in Spring Boot docs (Chapter 68.3) which works, but (as documented) this way is like the 'poor man approach' and I'd really like to use Flyway also for these tables containing the User/Group/Authorities information.
Ok, after some further investigation I've found the problem:
Indeed, in a standard Spring Boot project the security context is initialized before any Flyway based migration takes place.
Normally this is not a big issue, but I've also used the AuthenticationManagerBuilder for creating a default admin user. This seems to be the wrong approach for creating such an initial user account.
jOOQ should be an alternative to standard JPA. Is there any way to use it in Roo as JPA provider? Is it even possible?
The reason for this: We have Oracle database and jOOQ has quick and easy set up for connection to that database. On the other hand, Roo is very usefull tool but lacks on setting up Oracle database connection.
jOOQ doesn't implement JPA. It just happens to support a few JPA annotations, which is far from actually implementing JPA. In other words, no you cannot use jOOQ as a JPA provider in Spring Roo