Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am getting an exception when my column name contains 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 the query for schema creation.

    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)

Could some one help me in fixing this?

like image 868
Ram Subramanian Avatar asked Apr 27 '15 20:04

Ram Subramanian


2 Answers

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

You have two possible solutions:

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

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

I strongly recommend using underscores instead of dashes, you never know what weirdness different JPA implementations might have when using the second solution.

like image 78
RudolphEst Avatar answered Jan 04 '23 17:01

RudolphEst


Check your configuration file has correct provider, I fixed same issue by providing org.hibernate.ejb.HibernatePersistence provider.

like image 29
Jayen Chondigara Avatar answered Jan 04 '23 16:01

Jayen Chondigara