I have configured H2 as follows for my springboot app:
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
# Enabling H2 Console
spring.h2.console.enabled=true
# Custom H2 Console URL
spring.h2.console.path=/h2
When I go to log in it says it cannot find the database. I am typing explicitly jdbc:h2:mem:testdb like this:
What else can I do to troubleshoot? I do have a data.sql file which is creating the schema and putting in sample data.
I read through some other tutorials which mentioned including jdbc or jpa in maven/gradle. When I added either of these then H2 seemed to work just fine.
Had same problems, what I did to make this work was:
application.properties:
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.datasource.url=jdbc:h2:mem:uniqueNewName <<testdb did not work!
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
springspring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
pom.xml:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc10 -->
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc10</artifactId>
<version>19.8.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
Don't ask me why, but I had to add jbdc and spring-boot-starter-data-jpa to my dependencies to make this work.
Related
I have setup oracle as a database, I'm connected to it and can do CRUD operations using spring boot, however, the data.sql file in the resources folder doesn't seem to get excuted
spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.hibernate.ddl-auto=none
spring.jpa.generate-ddl=false
spring.datasource.initialization-mode=always
this is my jpa properties, and this is my jpa dependency
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
You have to add
spring.sql.init.mode=always
Here's a guide to this topic: https://www.baeldung.com/spring-boot-data-sql-and-schema-sql
I've seen variations of this subject multiple times around, but the answers never solved my case: I've been adding the H2 console to my WebFlux application (Spring Boot 2.6.3) and could connect to it; but couldn't see any of my tables in my JDBC schema. Thing is... My controller is working fine and I can retrieve from my endpoint the expected structure and data I did setup into shema.sql et data.sql
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>me.yaman.can</groupId>
<artifactId>spring-boot-webflux-h2-console</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
These are my properties : I'm connecting to localhost:8080/h2-console and am being redirected to localhost:8081/ all right
spring.datasource.url=jdbc:h2:mem:pocdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=foobar
spring.datasource.driverClassName=org.h2.Driver
spring.h2.console.enabled=true
spring.h2.console.port=8081
spring.h2.console.path=/h2-console
As I said, the connection to the console is OK, with my "pocdb" schema declared in the login URL; but I can't see any custom tables in here :-(
I also tried with and without the db url parameters but nothing changes. IF somebody has any clue about what I'm doing wrong, I'd be relieved to here it. Thx
Hibernate is generating temporary tables for TABLE_PER_CLASS inheritance but the prod. oracle user does not have those create table priviledges and therefore that approach is not an option for our project.
Hibernate Version 5.2.8 is said to resolve that issue.
We updated our pom.xml accordingly to override default starter hibernate version setting.
Still we dont have any luck with the following property.
<property name="hibernate.hql.bulk_id_strategy"
value="org.hibernate.hql.spi.id.inline.InlineIdsInClauseBulkIdStrategy"
/>
APPLICATION PROPERTIES is also updated as follows
**
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=jdbc:oracle:thin:#192.168.1. :1521:
spring.datasource.username=
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=none
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.hql.bulk_id_strategy=org.hibernate.hql.spi.id.inline.InlineIdsInClauseBulkIdStrategy
**
Where is the proper location of this setting in a spring boot app?
The container is still generating temp tables in the test env. server startup.
kind regards
pom.xml is as follows
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>x.xx.ortakonline</groupId>
<artifactId>PolsanOrtakOnlineServer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.0.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<jjwt.version>0.7.0</jjwt.version>
<hibernate.version>5.2.8.Final</hibernate.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope> test </scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
<dependency>
<groupId>org.springframework.mobile</groupId>
<artifactId>spring-mobile-device</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
</dependency>
</dependencies>
In addition all properties in spring.jpa.properties.* are passed through as normal JPA properties (with the prefix stripped) when the local EntityManagerFactory is created.
This comes from the JPA section in the Spring Boot reference guide and, in a nutshell, explains how to pass additional provider specific properties.
Adding the following to your application.properties should do the trick
spring.jpa.properties.hibernate.hql.bulk_id_strategy=org.hibernate.hql.spi.id.inline.InlineIdsInClauseBulkIdStrategy
As suggested by M.Deinum above, you should add the following to your application.properties file:
spring.jpa.properties.hibernate.hql.bulk_id_strategy=org.hibernate.hql.spi.id.inline.InlineIdsInClauseBulkIdStrategy
and also add the following to the properties section of your pom.xml to override the bundled hibernate-core library. This is to ensure that the InlineIdsInClauseBulkIdStrategy class is found, as the class is only available in Hibernate Core 5.3.1.Final and above:
<properties>
...
<hibernate.version>5.3.1.Final</hibernate.version>
</properties>
im trying to connect my Spring Boot app to a Cassandra 2.2.8 cluster on EC2 instances (2 nodes).
my use is tracing with Sleuth and Zipkin.
when the tracing start, the driver always point to localhost :
com.datastax.driver.core.Cluster : New Cassandra host localhost/127.0.0.1:9042 added
this is my application.properties
spring.datasource.url=jdbc:cassandra://url-node-1:9042
spring.datasource.contactPoints=url-node-1,url-node-2
zipkin.storage.type=cassandra
spring.datasource.initialize=true
spring.datasource.continue-on-error=true
spring.sleuth.enabled=false
and this is my pom.xml :
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-storage-cassandra</artifactId>
<version>1.17.1</version>
<exclusions>
<exclusion>
<artifactId>cassandra-driver-core</artifactId>
<groupId>com.datastax.cassandra</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>3.1.0</version>
</dependency>
Zipkin's connection to cassandra is independent from the normal spring setup. We use some very specific setup. you'll want to set properties in the namespace of zipkin.storage.cassandra
https://github.com/openzipkin/zipkin/blob/master/zipkin-server/src/main/resources/zipkin-server-shared.yml#L40
I have a small application (spring 4.0, jpa 2.1, hibernate 5.0.2) and had been using "old" java.util.Date* classes as well as java.sql.Date*. Now I wanted to use java.time instead and read that it would work with an AttributeConverter.
Unfortunately this doesn't seem to work. The moment I try to read the database object with a timestamp (the doa has an equivalent of java.time.localdatetime) I get an exception.
It seems the Converter isn't being used at all even though the annotation is there. I only have an applicationContext.xml and no persistence.xml so where would I tell jpa to use the Converter (if the annotation isn't enough)?
How can I see that the AttributeConverter is picked up by jpa at all?
Thanks in advance,
John.
#Converter is available in JPA2.1 .
Try to change your dependency config:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.5.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.7.2.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.5.Final</version>
</dependency>