Fix liquibase and Orient DB compatibility - java

I upgraded liquibase version in my Spring Boot App from 3.10.2 to 4.17.2 and I'm getting error
Suppressed: com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error parsing query: CREATE TABLE DATABASECHANGELOGLOCK (ID INT NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED datetime, LOCKEDBY VARCHAR(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID)) Encountered " <CREATE> "CREATE "" at line 1, column 1.Was expecting one of:
<LET> ...
<EXPLAIN> ...
DB name="mdp"
Error Code="1"
at com.orientechnologies.orient.core.sql.parser.OStatementCache.throwParsingException(OStatementCache.java:155)
at com.orientechnologies.orient.core.sql.parser.OStatementCache.parse(OStatementCache.java:147)
at com.orientechnologies.orient.core.sql.parser.OStatementCache.get(OStatementCache.java:86)
at com.orientechnologies.orient.core.sql.parser.OStatementCache.get(OStatementCache.java:65)
at com.orientechnologies.orient.core.sql.OSQLEngine.parse(OSQLEngine.java:80)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentEmbedded.command(ODatabaseDocumentEmbedded.java:650)
at com.orientechnologies.orient.server.OConnectionBinaryExecutor.executeQuery(OConnectionBinaryExecutor.java:1489)
at com.orientechnologies.orient.client.remote.message.OQueryRequest.execute(OQueryRequest.java:143)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.sessionRequest(ONetworkProtocolBinary.java:355)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.execute(ONetworkProtocolBinary.java:239)
at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:67)
As I can see liquibase can not create his own tables. I started getting this error after version update.
Can somebody tell me what can be a reason and how can I fix it. I can provide any information about my app whatever you need. Thanks!

Related

Liquibase is trying to create the databasechangelog table again

In my project I have scripts that create tables, make changes, and so on, now when I add a new migration in a new file in the changeLog, I get an error. In the last migration that I added, there are no errors, because if you delete all tables from the schema and run the project, then everything will work without problems. But this option is not suitable, as a rule. The error occurs precisely when adding a new migration on top of the old one.
[ERROR] Error setting up or running Liquibase:
[ERROR] ??????: ????????? "databasechangelog" ??? ?????????? [Failed SQL: (0) CREATE TABLE databasechangelog (ID VARCHAR(255) NOT NULL, AUTHOR VARCHAR(255) NOT NULL, FILENAME VARCHAR(2
55) NOT NULL, DATEEXECUTED TIMESTAMP WITHOUT TIME ZONE NOT NULL, ORDEREXECUTED INTEGER NOT NULL, EXECTYPE VARCHAR(10) NOT NULL, MD5SUM VARCHAR(35), DESCRIPTION VARCHAR(255), COMMENTS V
ARCHAR(255), TAG VARCHAR(255), LIQUIBASE VARCHAR(20), CONTEXTS VARCHAR(255), LABELS VARCHAR(255), DEPLOYMENT_ID VARCHAR(10))]
I use spring boot, postgres in my project. What do you think might be the problem? thanks in advance.
left it in the form of a screen too, suddenly it will be more convenient for someone)
If you already have those spring configurations in your property file, It will create the liquibase tables. Make sure you are not creating it manually again in other liquibase script.
spring.liquibase.database-change-log-lock-table = DATABASECHANGELOGLOCK
spring.liquibase.database-change-log-table = DATABASECHANGELOG

Switching from H2 to PostgreSQL with spring boot

I have a spring boot application working fine on a H2 DB. If I want to switch to postgresQL I get errors.
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
Errors:
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "drop table if exists
user cascade" via JDBC Statement
...
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "user"
...
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table user (id int8 not null, active int4 not null, first_name varchar(255), last_name varchar(255), password varchar(255), role varchar(255), username varchar(255), primary key (id))" via JDBC Statement
I think this is because user is a reserved word in PostrgeSQL.
In order to create a table with such name, try quote it (that is, create table "user"...)
Enclosing all the objects' names in 'ANSI quotes' is generally a good idea if you want an interoperability between different databases.

H2 SQL Syntax Error `expected "., COMMENT, ("` using Flyway w/ Spring Boot Test

I am using Spring Boot 2 with Data JPA and Flyway on a Postgres database. Everything works fine in production. Now I'm trying to write tests that will run on an H2 Embedded Database for testing purposes. But, the tests encounter a SQL syntax error. But, I don't understand what's wrong with the syntax:
CREATE TABLE mysite_user (
id int8 NOT NULL,
thirdparty_user_id varchar(255) NULL,
email varchar(255) NULL,
first_name varchar(255) NULL,
PRIMARY KEY (id)
);
CREATE INDEX mysite_user_thirdparty_user_id_idx ON mysite_user USING btree (thirdparty_user_id) ;
This is the error:
Migration V1__Initial.sql failed
--------------------------------
SQL State : 42001
Error Code : 42001
Message : Syntax error in SQL statement "CREATE INDEX MYSITE_USER_THIRDPARTY_USER_ID_IDX ON MYSITE_USER USING[*] BTREE (THIRDPARTY_USER_ID) "; expected "., COMMENT, ("; SQL statement:
CREATE INDEX mysite_user_thirdparty_user_id_idx ON mysite_user USING btree (thirdparty_user_id) [42001-199]
Location : db/migration/V1__Initial.sql (/Users/me/Development/mysite-website/target/classes/db/migration/V1__Initial.sql)
Line : 20
Statement : CREATE INDEX mysite_user_thirdparty_user_id_idx ON mysite_user USING btree (thirdparty_user_id)
What am I doing wrong?
Arguably, what you're doing wrong is using different databases between prod and test. As you've seen, your tests end up having to be coded around the differences between the databases, as well as potentially overlooking subtle edge cases which work in one db and not the other.
If you want to go down this route it is possible - see Best way for "database specific" sql scripts with Flyway

Can't create table in DB2

I can't create the table in DB2 via Eclipse. I've been stuck for a long time and I've searched a lot for the following error:
Error SQLCODE=-204
Below is my code:
CREATE TABLE BaseEntity(
wts Timestamp NOT NULL,
siteID NOT NULL,
oid varchar2(11),
PRIMARY KEY (oid),
AccelerationVector varchar2(8),
DeadReckoningAlgorithm varchar2(8),
Orientation varchar2(8),
WorldLocation varchar2(8),
VelocityVector varchar2(8)
)
com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=NOT, DRIVER=3.63.123
at com.ibm.db2.jcc.am.fd.a(fd.java:679)
at com.ibm.db2.jcc.am.fd.a(fd.java:60)
at com.ibm.db2.jcc.am.fd.a(fd.java:127)
at com.ibm.db2.jcc.am.ho.b(ho.java:2317)
at com.ibm.db2.jcc.am.ho.c(ho.java:2300)
at com.ibm.db2.jcc.t4.cb.l(cb.java:370)
at com.ibm.db2.jcc.t4.cb.a(cb.java:62)
at com.ibm.db2.jcc.t4.q.a(q.java:50)
at com.ibm.db2.jcc.t4.tb.b(tb.java:220)
at com.ibm.db2.jcc.am.io.lc(io.java:3318)
at com.ibm.db2.jcc.am.io.b(io.java:4275)
at com.ibm.db2.jcc.am.io.dc(io.java:759)
at com.ibm.db2.jcc.am.io.executeUpdate(io.java:742)
at testDB.XmlToDBSchema.insertIntoDB(XmlToDBSchema.java:37)
at testDB.XmlToDBSchema.createDBSchma(XmlToDBSchema.java:191)
at testXMLPar.testXML.main(testXML.java:16)
The error -204 refers to an undefined name which can have several reasons. See here for an overview. In your case the statement has several issues:
siteID does not have a type,
primary key is in the middle of the statement, this should be moved to the end
varchar2 can only be used if the database has been enabled for it, else you may get this error messages
To correct the errors you have to rewrite the statement, use data types where needed and to make sure that varchar2 support is enabled (check get db cfg).

SQL syntax error initializing DB before unit Tests

I have created a .sql for preparing my DB for testing.
here a part of the .sql which produces the error:
DROP TABLE IF EXISTS announcement;
CREATE TABLE announcement (
id int(11) NOT NULL AUTO_INCREMENT,
date datetime DEFAULT NULL,
title varchar(255) DEFAULT NULL,
content mediumtext,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
LOCK TABLES announcement WRITE;
INSERT INTO announcement VALUES (1,'2015-07-29 10:59:16','Test Anno ','some text');
UNLOCK TABLES;
when executed in Mysql Workbench this scipt works fine.
however when executed via hibernate:
String sqlScript = readFile("dump.sql", Charset.forName("UTF8"));
//System.err.println(sqlScript);
Query q = em.createNativeQuery("BEGIN " + sqlScript + "END;");
q.executeUpdate();
I get:
2015-08-06 16:15:55 ERROR SqlExceptionHelper:146 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DROP TABLE IF EXISTS announcement;
CREATE TABLE announcement (
id int(11) NO' at line 1
I am using:
Properties jpaProperties = new Properties();
jpaProperties.put("hibernate.dialect","org.hibernate.dialect.MySQL5Dialect");
jpaProperties.put("hibernate.enable_lazy_load_no_trans", true);
Can someone help me out here?
thanks.
As stated by mustaccio BEGIN and END statements are not allowed outside of stored procedueres. See: Hibernate multiple native SQL statements

Categories

Resources