Spring Boot JPA with not a well known database - spring

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

Related

Can a single Spring boot/Spring data application have repo of Posgres and MongoDB

I am having a need where in a same spring boot application I need to use repo of Spring Data Mongo and Spring data jpa (postgres), during my initial testing I got runtime errors. While I debug more just wanted to check in same Spring Data Application can it have both repos for Postgres and MongoDB ?
Yes, you can have, make sure to add all dependency and create separate repositories for each data connection. I used MongoDB and MySql database it is working fine.

spring data jpa and jpa implementation

As we know that, spring data jpa just adds extra layer on jpa provider. Spring community provides some spring data jpa starter example here
https://spring.io/guides/gs/accessing-data-jpa/#initial
I didn't see any jpa provider used in this example, how could that happen?
Thanks
Spring boot provide jpa
For example, if you want to use Spring and JPA for database access, it is sufficient if you include spring-boot-starter-data-jpa dependency in your project.

Show Sql in spring jdbc applications

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.

Spring JPA PostgreSQL + MongoDB

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)

Petclinic hibernate.dialect for HSQL

I am trying to understand Spring Petclinic Application.
By default it seems that HSQL database and JPA is used, but I am unableto to find where the Hibernate Dialect for HSQL is mentioned in the application.
I understand that it is a mandatory property for Hibernate.
Kindly suggest
What about where org.hibernate.dialect.HSQLDialect and where the driver is org.hsqldb.jdbcDriver. Normally, if this is a Spring application, this will be present in an applicationContext.xml or tx-datasource.xml configuration file. Whatever is the case, these properties must be in one of the XML Spring configuration files. Of course, they may be in a Java class (an alternative), but in most applications, they are present in Spring XML files where the dataSource bean is defined. Usually, in web applications, that would be in directory under /WEB-INF or /webapp/WEB-INF.

Resources