Junit HSQLDB - user does not have privilege or object not found - THIS_.oh-ordnbr

I get an exception when my column name contains a hyphen "-"

Entity : this is the entity name. @Entity @Table(name = "RequestHeader") public class RequestHeader implements Serializable { .... .... @Column(name = "`oh-ordnbr`") private Integer ohOrdnbr; 

Schema Definition: This is a schema creation request.

  CREATE MEMORY TABLE PUB.REQUESTHEADER( REQUESTID INTEGER, IMUSERID INTEGER, REQUESTDATE DATE, REQUESTTIME INTEGER, REQUESTSTATUS VARCHAR(19), REQUESTTYPE VARCHAR(22), HEADERINSTRUCTIONS VARCHAR(5150), DATEFORMAT VARCHAR(20), TIMEFORMAT VARCHAR(20), LANGUAGEID INTEGER, "OH-ORDNBR" INTEGER, "OH-TRCNSTAMP" INTEGER, ISPICKUPLIST BIT(1), CONSTRAINT "RQH-1" PRIMARY KEY(REQUESTID) ); 

The error is below:

 Exception Stack: Error message which I have received by running the Junit. Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: THIS_.oh-ordnbr at org.hsqldb.error.Error.error(Unknown Source) at org.hsqldb.error.Error.error(Unknown Source) at org.hsqldb.ExpressionColumn.checkColumnsResolved(Unknown Source) at org.hsqldb.QueryExpression.resolve(Unknown Source) at org.hsqldb.ParserDQL.compileCursorSpecification(Unknown Source) at org.hsqldb.ParserCommand.compilePart(Unknown Source) at org.hsqldb.ParserCommand.compileStatement(Unknown Source) at org.hsqldb.Session.compileStatement(Unknown Source) at org.hsqldb.StatementManager.compile(Unknown Source) at org.hsqldb.Session.execute(Unknown Source) 

Can someone help me fix this?

+7
hsqldb
source share
4 answers

The reason for the error not found is the fact that the oh-ordnbr column is defined as case sensitive (this is due to the double quotes that you place around it).

You have two possible solutions:

  • Do not use dashes (hyphens) in your SQL. It's bad practice anyway, use underscores instead.
  • Update the JPA annotation as follows:

      @Column(name = "`OH-ORDNBR`") private Integer ohOrdnbr; 

I highly recommend using underscores instead of dashes, you never know what oddities different JPA implementations can have when using the second solution.

+10
source share

Thank you for your responses. As you pointed out correctly, hsqldb is case sensitive. I changed the schema definition and now it worked. Since we are using pre-existing db, we cannot change the code. Therefore, I am changing the scheme in the same way as the existing db.

+2
source share

If HSQL scripts are run through Java, and if each new query in the table is followed by select / alter / update queries, it always throws "user lacks privilege object." In fact, the creation of queries after execution with Java instructions is never entered into the database and is not saved, and we run our selection / change / update, and this leads to an exception. If we run queries in turn and commit for each row, we could avoid this error.

0
source share

Check that your configuration file has the correct provider, I fixed this problem by providing the provider org.hibernate.ejb.HibernatePersistence.

0
source share

All Articles