Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquibase update error

I am trying to create a few tables in a DB using Liquibase.

Some background: I executed the same changelog.xml file on a local h2 database and it worked succussfully. And I tested the below oracle database, username, password and driver with squirrel and it connected successfully. So I'm fairly certain that I am facing a liquibase problem. I did extensive google-ing and did not find anything on SO or anywhere else that could helped me.

I entered the following into the command prompt:

C:\>java -jar liquibase-core-2.0.5.jar --driver=oracle.jdbc.OracleDriver
--classpath=ojdbc6-11.2.0.3.0.jar --changeLogFile=changelog.xml 
--url="jdbc:oracle:thin:@myDatabase"
--username=myUsername --password=myPassword --logLevel=debug update

Which returned:

DEBUG 9/30/13 3:09 PM:liquibase: Unable to load/access Apache Derby driver class
to check version
DEBUG 9/30/13 3:09 PM:liquibase: Connected to myUsername@jdbc:oracle:thin:@myDatabase
DEBUG 9/30/13 3:10 PM:liquibase: Executing QUERY database command: SELECT LOCKED
FROM DATABASECHANGELOGLOCK WHERE ID=1 FOR UPDATE
Liquibase Update Failed: Empty result set, expected one row
SEVERE 9/30/13 3:10 PM:liquibase: Empty result set, expected one row
liquibase.exception.LockException: liquibase.exception.DatabaseException: Empty
result set, expected one row
    at liquibase.lockservice.LockService.acquireLock(LockService.java:121)
    at liquibase.lockservice.LockService.waitForLock(LockService.java:61)
    at liquibase.Liquibase.update(Liquibase.java:102)
    at liquibase.integration.commandline.Main.doMigration(Main.java:825)
    at liquibase.integration.commandline.Main.main(Main.java:134)
Caused by: liquibase.exception.DatabaseException: Empty result set, expected one
row
    at liquibase.util.JdbcUtils.requiredSingleResult(JdbcUtils.java:124)
    at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:
159)
    at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:
167)
    at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:
163)
    at liquibase.lockservice.LockService.acquireLock(LockService.java:96)
    ... 4 more
like image 255
user821863 Avatar asked Oct 01 '13 14:10

user821863


4 Answers

if your DATABASECHANGELOGLOCK is empty, the error will always appear. (I had this problem after accidentally remove the records of this table).

The solution I found was simple:

just insert a dummy row with ID=1, LOCKED=0, LOCKGRANTED=null, LOCKEDBY=null

That's it!

like image 98
sergioviniciuss Avatar answered Nov 07 '22 12:11

sergioviniciuss


In my case the problem was that I had used

<dependency>
    <groupId>postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>9.1-901-1.jdbc4</version>
</dependency>

instead of

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.2.5</version>
</dependency>

for PostgreSQL 10.6. That solved the problem

like image 23
Maciej Tułaza Avatar answered Nov 07 '22 10:11

Maciej Tułaza


I found the answer here: https://forum.liquibase.org/t/message-regarding-an-empty-result-set-for-databasechangeloglock/1487/2

Deleting the databasechangeloglock table solved it for me.

like image 22
user821863 Avatar answered Nov 07 '22 12:11

user821863


We have experienced a problem with the same core exception when trying to use liquibase using postgresql 10.4:

Caused by: liquibase.exception.DatabaseException: Expected single row from 
liquibase.statement.core.GetViewDefinitionStatement@1de5f25 but got 0`

It seemed that for us it was a problem with our jdbc driver.

The solution for us was to upgrade the jdbc driver from 9.3-1102-jdbc41 to 9.4-1202-jdbc41.

like image 4
Giorgos Gaganis Avatar answered Nov 07 '22 11:11

Giorgos Gaganis