I am using Axon Framework 4.1 (without Axon Server) with Oracle 12.1 and Spring Boot Jpa 2.3.0
When the application starts I am using hibernate via this property spring.jpa.hibernate.ddl-auto=create to generate all my tables including Axon's tables. As a result I got the names in this format DOMAIN_EVENT_ENTRY, TOKEN_ENTRY etc..
After that, when I send a command, I got the following error message: An event for aggregate [2] at sequence [0] could not be persisted.
I think this is because Axon searching for the table with the name: DOMAINEVENTENTRY and not finding it and I got the error message. When I renamed DOMAIN_EVENT_ENTRY table to DOMAINEVENTENTRY everything started working well.
If I guess well this is the problem. But on the other hand I used Axon with H2 and it worked with the name DOMAIN_EVENT_ENTRY, so I guess its an Oracle specific issue?
So my question is how can I configure the Axon tables name to generate the tables in the right name without hacking.
And think it would be good in this case a more detailed error message. Why my event can't be persisted.
My properties related with the question:
hibernate.dialect=org.hibernate.dialect.Oracle12cDialect
spring.jpa.hibernate.ddl-auto=create
spring.jpa.generate-ddl=true
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver.class=oracle.jdbc.driver.OracleDriver
Thanks,
Mate
UPDATE
Here is the answer:
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
This create the tables in this style: DOMAINEVENTENTRY etc..
Related
I stumbled upon a strange error today. One of my Java Persistence Application programming interface (JPA) entities in Spring Boot application is not working. I tracked the problem down to a single column:
#javax.persistence.Column(name = "NameWrittenInPascalCase")
java.lang.String c;
When I checked the Structured Query Language (SQL) query which Spring Boot/Hibernate generates I discovered the problem. It seams that Spring Boot or Hibernate converts the NameWrittenInPascalCase into name_written_in_pascal_case (just written in snake case). (In database, of course, my column name is written in PascalCase).
For gods sake, why?
And how to prevent it from doing so?
If you need aditional info, I use Spring Boot version 2.5.7.
in your project application.properties file set the naming strategy:
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.EJB3NamingStrategy
Default value is org.springframework.boot.orm.jpa.SpringNamingStrategy
UPDATE:
If previous property does not solved your problem, you can use this one (For newer versions of Hibernate):
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
I have a problem with the Spring Framework. It doesn't create the database automatically on startup. I read the HowTo-Guides of Spring on how to initialize the database and followed these steps, but it doesn't work. I also searched around the web for similar problems, but I didn't find anything which could help me.
Error description:
On startup of the Server, I get an Errormessage:
FATAL: Datenbank »money_man_api_db« existiert nicht (German)
FATAL: Database »money_man_api_db« does not exist (English translation)
My configuration:
application.properties:
server.port=3000
# Basic Connection Configuration
spring.datasource.hikari.connection-timeout=20000
spring.datasource.hikari.maximum-pool-size=5
# PostgreSQL Configuration
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.datasource.initialization-mode=always
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/money_man_api_db
spring.datasource.username=postgres
spring.datasource.password=admin
Why doesn't the database get initialized? Did I forget something?
First you should create a database, later on you can connect to this database.
The title is misleading because Hibernate will not create a database, but will create the tables in this database. Hibernate is an ORM, it will create compatible SQL queries to interact with the database.
It's a layer between your OO code and the database, that takes care of complexity of creating SQL queries and mapping them to your code.
More info can be found here: https://hibernate.org/orm/
I have a spring boot batch application. In application.properties, I specify my data source details as follows
spring.datasource.url=jdbc:jtds:sqlserver://1*.2**.6*.25:14**
spring.datasource.database=MYDB_DEV
spring.datasource.username=username
spring.datasource.password=password
The problem is, when I run the batch job, all user defined tables are taken from the MYDB_DEV. But Metadata tables like BATCH_JOB_EXECUTION, BATCH_JOB_EXECUTION_CONTEXT are taken from the MASTER schema even though I have created the same tables in MYDB_DEV. Why this happens? Is there any work around to make the application read Metadata tables from user defined schema?
I have debugged though the jobLauncher.run(myjob, jobParameters), Could not find any lead from where it is taking master Schema
Use below property in application.properties or application.yml
spring.batch.tablePrefix=MYDB_DEV.BATCH_
I have the following application.properties :
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url= ${DATASOURCE_URL}
spring.datasource.username= ${DATASOURCE_USERNAME}
spring.datasource.password= ${DATASOURCE_PASSWORD}
## Other Database
second.datasource.url="jdbc:oracle:thin:#localhost:1521:XE"
second.datasource.username=usr
second.datasource.password=password
second.datasource.driver-class-name=oracle.jdbc.OracleDriver
second.jpa.show-sql=true
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto = update
spring.jpa.database=default
Goal and things that currently work : The spring datasource at the top works fine. I am able to use that for all of my main needs. The second one, below it, is going to query a legacy system and get data from there.
Problem : I have no idea how to get that second datasource to work at all. I need to get it to perform a query and get it returning something. Ideally I would love to see an example of this that works. I looked at a few blog posts, and googled around, and I am clearly missing some vital information.
the above is default and spring can find it on its own. To create a different DataSource you need to setup a datasource bean somewhere, and read values from a config.
Easiest way would be to create a class with configuration annotation and define beans for both dataSources.
I'd suggest HikariDataSource, you can read more about how to set it up here: https://www.baeldung.com/hikaricp
For configuration you can use Environment by autowiring it and reading your properties from there.
environment.getProperty("second.datasource.url") for example
Check the instructions in this link: https://www.baeldung.com/spring-data-jpa-multiple-databases
1) You need to provide JPA configuration for each of your datasources with 2) independent entity packages for each of these sources and, 3) you must specify one of the data source as Primary.
When I use in-memory(h2) database, spring-data-jpa is creating tables, but, when I change datasource to point to MS SQL (2017), I cannot see tables getting created.
Can anyone help me to solve this scenario?
Note: I'm using spring boot in my project
Make sure you configured: spring.jpa.hibernate.ddl-auto=update
It's hibernate how creates tables and not Spring Data JPA.