HSQL database user lacks privilege or object not found error HSQL database user lacks privilege or object not found error spring spring

HSQL database user lacks privilege or object not found error


user lacks privilege or object not found can have multiple causes, the most obvious being you're accessing a table that does not exist. A less evident reason is that, when you run your code, the connection to a file database URL actually can create a DB. The scenario you're experiencing might be you've set up a DB using HSQL Database Manager, added tables and rows, but it's not this specific instance your Java code is using. You may want to check that you don't have multiple copies of these files: mydb.log, mydb.lck, mydb.properties, etc in your workspace. In the case your Java code did create those files, the location depends on how you run your program. In a Maven project run inside Netbeans for example, the files are stored alongside the pom.xml.


As said by a previous response there is many possible causes. One of them is that the table isn't created because of syntax incompatibility. If specific DB vendor syntax or specific capability is used, HSQLDB will not recognize it. Then while the creation code is executed you could see that the table is not created for this syntax reason. For exemple if the entity is annoted with @Column(columnDefinition = "TEXT") the creation of the table will fail.

There is a work around which tell to HSQLDB to be in a compatible modefor pgsl you should append your connection url with that

"spring.datasource.url=jdbc:hsqldb:mem:testdb;sql.syntax_pgs=true"

and for mysql with

"spring.datasource.url=jdbc:hsqldb:mem:testdb;sql.syntax_mys=true"

oracle

"spring.datasource.url=jdbc:hsqldb:mem:testdb;sql.syntax_ora=true" 

note there is variant depending on your configuration it could be hibernate.connection.url= or spring.datasource.url=for those who don't use the hibernate schema creation but a SQL script you should use this kind of syntax in your script

SET DATABASE SQL SYNTAX ORA TRUE;

It will also fix issues due to vendor specific syntax in SQL request such as array_agg for posgresql

Nota bene : The the problem occurs very early when the code parse the model to create the schema and then is hidden in many lines of logs, then the unitTested code crash with a confusing and obscure exception "user lacks privilege or object not found error" which does not point the real problem at all. So make sure to read all the trace from the beginning and fix all possible issues


If you've tried all the other answers on this question, then it is most likely that you are facing a case-sensitivity issue.

HSQLDB is case-sensitive by default. If you don't specify the double quotes around the name of a schema or column or table, then it will by default convert that to uppercase. If your object has been created in uppercase, then you are in luck. If it is in lowercase, then you will have to surround your object name with double quotes.

For example:

CREATE MEMORY TABLE "t1"("product_id" INTEGER NOT NULL)

To select from this table you will have to use the following query

select "product_id" from "t1"