How do I find out which schema script spring-boot is running? - spring-boot

I have an application based on spring-boot 1.4 with spring-jdbc.
I've added Flyway, which works in the application itself, but I get errors for my JdbcDAO test cases.
Question: I know spring-boot overrides 'dataSource' to embedded HSQLDB datasource, but I have no idea where it finds the SQL scripts to populate the empty database when I run tests.
Documentation says that it looks for 'schema.sql' or 'data.sql' in classpath, but I've renamed all of the script files in both main and test resource paths, but I still get this error:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed;
nested exception is org.flywaydb.core.api.FlywayException: Found non-empty schema(s) "PUBLIC" without schema history table! Use baseline() or set baselineOnMigrate to true to initialize the schema history table.
This error leads me to believe that Spring-boot had created a schema definition BEFORE Flyway scripts were applied.
UPDATE: I'm getting a different error now, this is a Bad SQL error:
org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [INSERT INTO BLUECOST_SSCDATA (SSCDATAID,PROCESSGROUPID,COSTINGAMOUNT,CHRG_TYP_CD,CONTROL_GROUP_CD,ACCOUNT_ID,CHRGHS_END_DT,ORIG_LOC_CD,SERVICE_TYP_CD,SERVICE_CD,SERVICE_GROUP_ID,SERVICE_ENV_CD,SERVICE_ADDER_CD,SERVICE_RESTYP_CD,RATECLAS_CD,PRICELST_UP_AMT,CHRGHS_USAGE_QTY,EMP_FA_CD,EMP_DIV_CD,EMP_DPT_CD,EMP_COUNTRY_CD,EMP_COMPANY_CD,EMP_NUM,EMP_INITS,EMP_LASTNAME,USER_ID,ADJUSTMENT_ID,CUST_REFERENCE_ID,ORIG_DIV_CD,ORIG_DPT_ID,ORIG_COUNTRY_CD,ORIG_COMPANY_CD,LOCAL_FIELD_1,LOCAL_FIELD_2,LOCAL_FIELD_3,LOCAL_FIELD_4,LOCAL_FIELD_5,LOCAL_FIELD_6,CREATETIME,PROCESSTIME,LAST_ALTER_TMS,TRX_TYP_CD,FILENAME) VALUES (100,null,368.60,'CTA','EMEA ','D286148 ','2018-03-19','SLR','SLR','SLIC','BASE',null,null,null,'OGS',null,null,null,null,null,null,null,null,null,'IBM SLIC BV',null,null,null,null,null,'653','SOFTLAYR','INVCE ID','X91927','ACCNT ID','FILENAME1.XLS',null,null,{ts '2018-04-22 01:30:21.437000'},null,{ts '2018-03-22 01:32:21.437000'},'I','FILENAME1.XLS')]; nested exception is java.sql.SQLSyntaxErrorException: requires either DEFAULT keyword or OVERRIDING clause
at com.ibm.cio.cloud.cost.spreadsheet.dao.UTJdbcBluecostSSCDataDAOTest.testDeleteBluecostSSCDataByLocalField2AndLocalField4(UTJdbcBluecostSSCDataDAOTest.java:265)
Caused by: java.sql.SQLSyntaxErrorException: requires either DEFAULT keyword or OVERRIDING clause
at com.ibm.cio.cloud.cost.spreadsheet.dao.UTJdbcBluecostSSCDataDAOTest.testDeleteBluecostSSCDataByLocalField2AndLocalField4(UTJdbcBluecostSSCDataDAOTest.java:265)
Caused by: org.hsqldb.HsqlException: requires either DEFAULT keyword or OVERRIDING clause
at com.ibm.cio.cloud.cost.spreadsheet.dao.UTJdbcBluecostSSCDataDAOTest.testDeleteBluecostSSCDataByLocalField2AndLocalField4(UTJdbcBluecostSSCDataDAOTest.java:265)
This gives me a clue: looks like my latest Flyway script is not applied to the schema when running the 'mvn test' goal.
How do I turn on the debugging to see what is happening with Flyway when running mvn test goal?

Fixed - retracting this question now.
<logger name="org.flywaydb" level="DEBUG">
<appender-ref ref="STDOUT"/>
</logger>

Related

liquibase.exception.DatabaseException: Syntax error in SQL statement " CREATE EXTENSION[*] UUID-OSSP;

Im using postgres with liquibase on cloud and h2db on my local machine. When i write sql queries for generating uuid, i get the error during build:
liquibase.exception.DatabaseException: Syntax error in SQL statement " CREATE EXTENSION[*] UUID-OSSP;
So i removed ossp extension and used gen_random_uuid() instead. And i get the below eror:
Caused by: liquibase.exception.LiquibaseException:
liquibase.exception.MigrationFailedException: Migration failed for change set db/scripts/123_Somescripts.sql::raw::includeAll:
Reason: liquibase.exception.DatabaseException: Syntax error in SQL statement "
I start getting this error during build when i include H2 DB dependency. Otherwise the build works fine.
BUT, even if build works fine, i get the error:
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Process finished with exit code 0
I configured postgres db in appication-local.yml, and activated local profile but build still fails.

H2 and flyway crush on tests after upgrade from gradle 4 to 6

I am in the process of upgrading from gradle 4 to 6.
This forced me to upgrade many stuff like spring, h2, mySql connector, etc..
Now I have this problem:
on runtime, using MySQL all works fine.
but on tests, I get:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in com.bluerbn.wallet.infra.SpringTestConfiguration: Invocation of init method failed; nested exception is org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateException:
Migration V9__fixIndex.sql failed
------------------------------------------------
SQL State : 42S22
Error Code : 42122
Message : Column "INDEX" not found; SQL statement:
ALTER TABLE table1 DROP INDEX ACC_INDEX [42122-200]
Location : db/migration/V9__fixIndex.sql (/Users/.../resources/db/migration/V9__fixIndex.sql)
Line : 1
Statement : ALTER TABLE table1 DROP INDEX ACC_INDEX
This is an old script that was working fine before the upgrade.
versions:
spring boot: 2.3.0
org.flywaydb:flyway-core:6.4.1 (though in gradle I put 6.4.2)
com.h2database:h2:1.4.200
mysql:mysql-connector-java:8.0.18
Any ideas?
H2 since the version 1.4.200 allows MySQL-style ALTER TABLE tableName DROP INDEX indexName only in MySQL compatibility mode. In 1.4.199 and older versions this invalid (for H2) command was incorrectly accepted in all modes.
You need to append ;MODE=MySQL to JDBC URL for H2.

flyway upgrade from 4.X to 5.x runs the already ran migration scripts again

I was upgrading springboot 2 from 1.5. For that, I upgraded the flyway from 4.X to 5.24. When I run the springboot application after that, it's executing scripts which were already executed. Below is the logs I am seeing. removing project specific names as I am not allowed to post it:
myproject INFO 2019-03-11T16:08:11-0400 main [org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory] Creating Schema History table: "PUBLIC"."flyway_schema_history"
myproject INFO 2019-03-11T16:08:11-0400 main [org.flywaydb.core.internal.command.DbMigrate] Current version of schema "PUBLIC": << Empty Schema >>
myproject INFO 2019-03-11T16:08:11-0400 main [org.flywaydb.core.internal.command.DbMigrate] Migrating schema "PUBLIC" to version 1 - CREATE mything
myproject ERROR 2019-03-11T16:08:11-0400 main [org.flywaydb.core.internal.command.DbMigrate] Migration of schema "PUBLIC" to version 1 - CREATE mything failed! Please restore backups and roll back database and code!
myproject WARN 2019-03-11T16:08:11-0400 main [org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateException:
Migration V1__CREATE_mything.sql failed
---------------------------------------
SQL State : 42509
Error Code : -5509
Message : type not found or user lacks privilege: SERIAL
I guess You are using default value for parameter table.name, which changed in v. 5.0.0.
Refer to https://flywaydb.org/documentation/releaseNotes
Issue 1848 The default for flyway.table has been changed from schema_version to flyway_schema_history

"Connection cannot be null when hibernate.dialect is not set" and sessionFactory error

I want to import in eclipse and connect with PostgreSQL database. PostgreSQL is configured on another machine.
I have imported the war file in eclipse and changed 3 file with IP address of the machine where PostgreSQL is installed. Three files were hibernate.cnf.xml, spring-database.xml, na-dispatcher.xml. Like
jdbc:postgresql://192.168.1.15:5432/mydatabase.
After that I tried running the application in tomcat server with eclipse IDE.
I got error like
./web-inf/sping-security.xml
1
Connection cannot be null when 'hibernate.dialect' not set
Also an error regarding session factory and all.
I can't paste the code because we can't use internet in office. Please help me in resolving this. Tomorrow is the deadline. no code
2
Error creating bean with name ‘sessionFactory’ defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set

A non-read-only mapping must be defined for the sequence number field

I am getting the following error from Toplink when I start my application. I am trying to add two new tables to our application.
EXCEPTION [TOPLINK-41] (TopLink - 9.0.3.7 (Build 440)): oracle.toplink.exceptions.DescriptorException
EXCEPTION DESCRIPTION: A non-read-only mapping must be defined for the sequence number field.
DESCRIPTOR: Descriptor(icis.cr.common.db.entities.ClerkReviewTask --> [DatabaseTable(CREV_TASK)])
I have compared the mappings to one that works and haven't noticed anything. I compared the new Class in TopLink workbench and don't see any missing mapping. It appears my sequence is mapped correctly. Does anyone have any suggestions with this?
The descriptor has the following for the TASK_ID field:
<primaryKeyFieldHandles>
<FieldHandle>
<table>CREV_TASK</table>
<fieldName>TASK_ID</fieldName>
</FieldHandle>
</primaryKeyFieldHandles>
<sequenceNumberName>SEQ_CREV_TASK_ID</sequenceNumberName>
<sequenceNumberFieldHandle>
<FieldHandle>
<table>CREV_TASK</table>
<fieldName>TASK_ID</fieldName>
</FieldHandle>
</sequenceNumberFieldHandle>
<Mapping>
<descriptor>icis.cr.common.db.entities.ClerkReviewTask.ClassDescriptor</descriptor>
<usesMethodAccessing>false</usesMethodAccessing>
<inherited>false</inherited>
<readOnly>false</readOnly>
<getMethodHandle>
<MethodHandle emptyAggregate="true">
</MethodHandle>
</getMethodHandle>
<setMethodHandle>
<MethodHandle emptyAggregate="true">
</MethodHandle>
</setMethodHandle>
<instanceVariableName>id</instanceVariableName>
<defaultFieldNames>
<defaultFieldName>direct field=</defaultFieldName>
</defaultFieldNames>
<fieldHandle>
<FieldHandle>
<table>CREV_TASK</table>
<fieldName>TASK_ID</fieldName>
</FieldHandle>
</fieldHandle>
<classIndicator>BldrDirectToFieldMapping</classIndicator>
</Mapping>
I was able to fix this by right-clicking my project in TopLink Mapping Workbench and selecting Export Project to Java Source. My file was out of date and caused this error and the following:
EXCEPTION [TOPLINK-110] (TopLink - 9.0.3.7 (Build 440)): oracle.toplink.exceptions.DescriptorException
EXCEPTION DESCRIPTION: Descriptor is missing for class [icis.cr.common.db.entities.ClerkReviewCaseTask].
MAPPING: oracle.toplink.mappings.OneToManyMapping[caseTasks]
DESCRIPTOR: Descriptor(icis.cr.common.db.entities.ClerkReviewTask --> [DatabaseTable(CREV_TASK)])

Resources