Using Spring-Boot-Starter-Web in combination with ObjectDB - java

I am implementing a program in Spring-Boot using ObjectDB. To actually use ObjectDB I have followed this approach which is working perfectly.
However, as soon as I want to use `spring-boot-starter-web`` then I am getting the following errors:
dataSource or dataSourceClassName or jdbcUrl is required. at
com.zaxxer.hikari.HikariConfig.validate
I have been fiddling around with parameter jdbc-url in the properties file as mentioned in many posts. Tried to exclude Hikari because probably ObjectDB uses his own connection pooling mechanism. But without any results.
Any ideas on how to solve this error?
I am using the exact same code as in the link. I have added Spring-Actuator in the pom like this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

In some cases, frameworks that use JPA require specifying a JDBC connection details, including a JDBC driver, which is then passed to the JPA implementation and used by it to access the database. ObjectDB is a JPA implementation that does not access an external database, and therefore, does not need or use a JDBC driver.
As discussed in the comments to the question, a simple workaround is to specify a dummy JDBC driver, which will be passed to ObjectDB and then ignored. It does look weird, but this is the way to go until either ObjectDB implement its own JDBC driver, or the relevant frameworks become more flexible regarding their request of a JDBC driver.

Have you tried this (in the pom.xml?):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.objectdb</groupId>
<artifactId>objectdb</artifactId>
<version>2.8.4</version>
</dependency>
And don't forget to add the database connection in application.properties:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=mydbuser
spring.datasource.password=mydbpass
spring.datasource.url=jdbc:....
See https://www.baeldung.com/the-persistence-layer-with-spring-and-jpa for more details.

Related

Can I use multiple and different databases in the same Quarkus app?

I want my Quarkus app to connect to both a PostgreSQL database and a MySQL database.
I've researched through https://quarkus.io/guides/datasource#multiple-datasources and https://quarkus.io/guides/hibernate-orm#multitenancy, but could not figure out if this is possible.
my application.properties is as below;
quarkus.datasource.postgresql.db-kind=postgresql
quarkus.datasource.postgresql.username=xyz
quarkus.datasource.postgresql.password=xyz
quarkus.datasource.postgresql.jdbc.url=jdbc:postgresql://localhost:5432/xyz
quarkus.datasource.mysql.db-kind=mysql
quarkus.datasource.mysql.username=xyz
quarkus.datasource.mysql.password=xyz
quarkus.datasource.mysql.jdbc.url=jdbc:mysql://localhost:3305/xyz
my pom.xml has both;
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-mysql</artifactId>
</dependency>
Is it possible to connect to multiple different types of database from Quarkus?
How do I persist() an Entity to the correct database if such capability exists?
Thank you!
What you are asking for is supported, see this part of the datasource documentation and this part of the Hibernate ORM documentation.

Connect to microsoft sql server from spring jpa

I am using microsoft sql server,
If i open intellij, open new database connection in database tool window =>
and in advanced type i add:
The connection works. However now i want to connect to this ms sql server with spring jpa. So what i am using is:
spring.datasource.url=jdbc:jtds:sqlserver://<host>:<port>;instance=<instance>;domain=<domain>;useNTLMv2=true
spring.datasource.username=<user>
spring.datasource.password=<password>
spring.datasource.driverClassName=net.sourceforge.jtds.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.SQLServerDialect
And it just says "login for user failed"
In my pom i am using:
<!-- jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring.jpa.version}</version>
</dependency>
<dependency>
<groupId>jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.2</version>
</dependency>
Why does it work with database tool window, but not with jpa?
Thanks for help!
Your are mixing JDBC driver connecting with sprig data JPA connection, for JPA proper connection you can change the drive class name to
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
Then the dialect can be
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
And finally add the proper url and remove JDBC driver relavent dependencies
spring.datasource.url=jdbc:sqlserver://localhost;databaseName=<dbname>
Remaining properties will be same as your, see both examples in here .

How can i create server side application for postgreSQL (for android app and no Firebase)

I'm a beginner at java and i'm developing a big app the big issue is that i need a big database for which i should make a server side application(which i don't know how) to connect to Postgres. I did not find anything about making it and connecting it to PostgreSQL to Android Studio for instance.. I'm really confused and can't find anything about the topic. Excuse my bad English.
I recomend to see this example https://spring.io/guides/gs/accessing-data-mysql/
Mysql is being used, but you could simple change the "jdbc driver" to connect with PostgreSQL
First change driver in pom.xml
this
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
to
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
</dependency>
and then replace the url in src/main/resources/application.properties with the connection info of your postgres instance.
spring.datasource.url=jdbc:postgresql://host:port/database
also add this line to the properties:
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
See https://github.com/spring-projects/spring-boot/issues/12007
On postgres user is a reserved keyword, so you have to change the name of the table that maps with User entity:
import javax.persistence.Table;
#Entity // This tells Hibernate to make a table out of this class
#Table(name = "users")
In this way you have the example working.
If not needed to do in Java, you can do it on other languages and frameworks, but the main idea would be to have an API and fetch or post data from/to.
I leave you some useful links to have more information
JDBC https://en.wikipedia.org/wiki/Java_Database_Connectivity
PostgreSQL JDBC Driver : https://github.com/pgjdbc/pgjdbc
ORM: https://en.wikipedia.org/wiki/Object-relational_mapping
Hibernate, a Java ORM http://hibernate.org/orm/
REST: https://spring.io/understanding/REST

Spring Boot-Activiti Integration with Sybase Database

I created a spring-boot project to read and write data to Sybase database. The project was working as intended. However, whenever I added activiti dependencies, It says "couldn't deduct database type from database product name 'Adaptive Server Enterprise'". According to my understanding, there are some classes conflicting each other in activiti and spring even though I do not use anything regarding activiti( except the fact that I just opened a folder called processes in the resources directory).
The activiti dependencies I added are:
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-rest-api</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-actuator</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-jpa</artifactId>
<version>5.21.0</version>
</dependency>
To clarify my point in this, I wanted to use activiti just for workflow purposes and leave the rest of the ETL or database job to spring. If I change database from Sybase to Mysql, the project also works fine even with activiti dependencies. As far as I know activiti has no support for Sybase and apparently, it tries to interfere everything possible and overrides something that was already working at the first place. How can I overcome this problem?
you are trying to use the spring boot starter which automatically tries to configure a database using spring autoconfiguration. Can you clarify with which database do you want to use Activiti? If you want to use Sybase you will need to contribute back to the project with Sybase support. Alternatively, you can not use the starter and depend on the engine directly, this will push you to provide the engine configurations for your spring environment. You can also check the -starter project and adapt as needed.
HTH

Is it possible to use CockroachDB with the Java Transaction API (JTA)?

I've seen the project via developpez.com
https://www.developpez.com/actu/118014/Cloud-Spanner-Google-lance-pour-le-grand-public-sa-solution-de-bases-de-donnees-globales-offrant-un-bon-compromis-entre-SQL-et-NoSQL/
CockroachDB seems to supports ACID transactions. So my question is:
Is it possible to use it with JPA and JTA?
CockroachDB is compatible with the JDBC API, via the Postgres pgjdbc driver. Since JPA and JTA connect to databases via JDBC, they should be useable against CockroachDB as long as you use the pgjdbc driver.
If you're using Maven, you can add the following declaration to your pom.xml to add a dependency on pgjdbc:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>VERSION</version>
</dependency>
Replace VERSION with a driver version selected from the list in Maven central.

Categories

Resources