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

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?

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:
Do not use dashes (hyphens) in your SQL. It is bad practice anyway, use underscores instead.
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.

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

If HSQL Scripts are run via Java and if any new table query is followed by select/alter/update queries it always throws "user lacks privilege object". In reality the create queries after execution with Java Statements never gets commited into the DB and it is not persisted and we run our select/alter/update and it results in the exception. If we run the queries line by line and commit for each line, we could avoid this error.

Related

WSO identity server , service provider creation with permissions does not work

I got following exception while creating new service provider with permissions , following is some portion of its code.
iManagementServiceStub = new IdentityApplicationManagementServiceStub();
iManagementServiceStub.createApplication(createApplication);
Following is exception i am getting on client side.
identity.IdentityApplicationManagementServiceIdentityApplicationManagementException: Error while storing permissions for application sp3
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at identity.IdentityApplicationManagementServiceStub.createApplication(IdentityApplicationManagementServiceStub.java:1007)
at identity.AddServiceProvider.main(AddServiceProvider.java:92)
Following are exception on server side.
Caused by: org.wso2.carbon.registry.core.exceptions.RegistryException: The path '/_system/governance/permission/applications/sp3/org.wso2.carbon.identity.application.common.model.ApplicationPermission#12809798' contains one or more illegal characters (~!##;%^*()+={}|\<>"',)
at org.wso2.carbon.registry.core.jdbc.Repository.put(Repository.java:262)
at org.wso2.carbon.registry.core.jdbc.EmbeddedRegistry.put(EmbeddedRegistry.java:717)
at org.wso2.carbon.registry.core.caching.CacheBackedRegistry.put(CacheBackedRegistry.java:591)
at org.wso2.carbon.registry.core.session.UserRegistry.putInternal(UserRegistry.java:828)
at org.wso2.carbon.registry.core.session.UserRegistry.putInternal(UserRegistry.java:796)
at org.wso2.carbon.registry.core.session.UserRegistry.access$900(UserRegistry.java:61)
at org.wso2.carbon.registry.core.session.UserRegistry$10.run(UserRegistry.java:786)
at org.wso2.carbon.registry.core.session.UserRegistry$10.run(UserRegistry.java:783)
at java.security.AccessController.doPrivileged(Native Method)
at org.wso2.carbon.registry.core.session.UserRegistry.put(UserRegistry.java:783)
at org.wso2.carbon.identity.application.mgt.ApplicationMgtUtil.storePermissions(ApplicationMgtUtil.java:299)
... 64 more
Please suggest.
When analyzing the error log, you can see that there are illegal charactors in your permission.
Caused by: org.wso2.carbon.registry.core.exceptions.RegistryException: The path '/_system/governance/permission/applications/sp3/org.wso2.carbon.identity.application.common.model.ApplicationPermission#12809798' contains one or more illegal characters (~!##;%^*()+={}|\<>"',)
Please check the permission name. Basically those charactors are reserved and have an specific use. So you cannot use them elsewhere whithout encoding them[1].
[1] https://en.wikipedia.org/wiki/Percent-encoding

JDBC | SQL Anywhere Error -188: Not enough values for host variables

JDBC or Hibernate is showing strange behavior while calling a stored procedure.
Here is the sample code:
return session.createSQLQuery("select * from pr_ss_coo_10x('31748','NEWRX',null,'5053')")
..
....tolist();
It is throwing error
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at org.hibernate.loader.Loader.doList(Loader.java:2620)
at org.hibernate.loader.Loader.doList(Loader.java:2600)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2429)
at org.hibernate.loader.Loader.list(Loader.java:2424)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:336)
at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1967)
at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:322)
at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:125)
at com.mps.surescript.repository.impl.SSGetInfoRepoImpl.getBenefitCoordInformation(SSGetInfoRepoImpl.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
... 76 common frames omitted
Caused by: com.sybase.jdbc3.jdbc.SybSQLException: SQL Anywhere Error -188: Not enough values for host variables
at com.sybase.jdbc3.tds.Tds.a(Unknown Source)
at com.sybase.jdbc3.tds.Tds.nextResult(Unknown Source)
However, it is working fine when I fire the same query through SQL Anywhere client. Sybase error code document says
"You have not provided enough host variables for either the number of
bind variables, or the statement, or the number of SELECT list items."
I have checked it twice and the result set is correctly mapped with the Pojo. What can be the possible root cause for this problem?
Bypassing the Hibernate transaction Management did the trick and fetching result set using PreparedStatement.
Connection con = DriverManager.getConnection(url, user, password);
PreparedStatement ps = con.prepareStatement(
"select * from pr_ss_coo_10x(#param1=?,#param2=?, #param3=?, #param4=? )");
ResultSet rs = ps.executeQuery();
This is not a solution, it is just a way around.

AEM 6.2- MongoDB: MSRP search results between given time range

I am trying to search for MSRP resources between given time range. I am trying to use below timeConstraint. (Made sure there are entries between that time range)
final Constraint timeConstraint = new RangeConstraint<Long>("timestamp_tl", until, cal.getTimeInMillis(), true);
"until" above is time in millis less than cal.getTimeInMillis(). Adding above timeConstraint to:
final ConstraintGroup mainConstraintGroup = new ConstraintGroup(Operator.And);
I added entries to MongoDB with additional property "timestamp_tl". Earlier I tried with just "timestamp".
In both cases I am getting error -
07.04.2017 17:08:00.100 *ERROR* [sling-default-4727-com.mycomp.proj.core.services.Mysearch.12850] com.mycomp.proj.core.services.MySearchTest Task failed!
java.lang.UnsupportedOperationException: Decimal searches not supported yet
at com.adobe.cq.social.sc.lucene.LuceneQueryFactory.getValueStringSolr(LuceneQueryFactory.java:554)
at com.adobe.cq.social.sc.lucene.LuceneQueryFactory.getValueString(LuceneQueryFactory.java:542)
at com.adobe.cq.social.sc.lucene.LuceneQueryFactory.getPropertyValueQuery(LuceneQueryFactory.java:511)
at com.adobe.cq.social.sc.lucene.LuceneQueryFactory.getComparisonQuery(LuceneQueryFactory.java:487)
at com.adobe.cq.social.sc.lucene.LuceneQueryFactory.mapConstraintToQueryAndFilter(LuceneQueryFactory.java:316)
at com.adobe.cq.social.sc.lucene.LuceneQueryFactory.mapConstraintToQueryAndFilter(LuceneQueryFactory.java:281)
at com.adobe.cq.social.sc.lucene.LuceneQueryFactory.mapConstraintToQueryAndFilter(LuceneQueryFactory.java:282)
at com.adobe.cq.social.sc.lucene.LuceneQueryFactory.getStatement(LuceneQueryFactory.java:164)
at com.adobe.cq.social.sc.lucene.QueryObjectModelImpl.getSelectorStatement(QueryObjectModelImpl.java:168)
at com.adobe.cq.social.sc.lucene.QueryObjectModelImpl.getStatement(QueryObjectModelImpl.java:109)
at com.adobe.cq.social.ugc.impl.LuceneUgcSearch.findCloudResources(LuceneUgcSearch.java:959)
at com.adobe.cq.social.ugc.impl.LuceneUgcSearch.find(LuceneUgcSearch.java:805)
at com.adobe.cq.social.ugc.impl.LuceneUgcSearch.find(LuceneUgcSearch.java:719)
at org.apache.sling.commons.scheduler.impl.QuartzJobExecutor.execute(QuartzJobExecutor.java:118)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Any suggestions on what I might be doing wrong?
Thanks
I found that I need to use
final Constraint timeConstraint = new RangeConstraint<Date>("timestamp", until, cal.getTime(), true);
Above 'until' and 'cal.getTime()' are java.util.Date objects. I was assuming the "timestamp" value saved in MongoDB is "long" value since it was displaying as "NumberLong("1492006094509")"

Failing jdbc INSERT INTO statement to MS Access database

statement.executeUpdate("INSERT INTO countrylookup (Country, DialCode) VALUES('Iran', '957')")
Running this statement gives me no error output in the console, but when I check the database no update/insert is made. What could be the reason for this?
The access to the database itself is successful, and fetching values with a statement such as SELECT * FROM countrylookup succeeds.
I tried the preparedStatement approach aswell with the exact same result. The file is not open when I execute the command.
UPDATE: Stacktrace: (first row in Swedish means "INSERT INTO-expression contains the following unknown fieldname: 'Pa_RaM000'. Please check that the name is rightly spelled and try again.)
Exception in thread "main" java.sql.SQLException: [Microsoft][Drivrutin f?r ODBC Microsoft Access] INSERT INTO-uttrycket inneh?ller f?ljande ok?nda f?ltnamn: 'Pa_RaM000'. Kontrollera att namnet ?r r?ttstavat och f?rs?k igen.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(Unknown Source)
at MDBAccessor.insertValueIntoField(MDBAccessor.java:43)
at TestRunner.main(TestRunner.java:28)
Is dialcode numeric? If so, remove the quotes from the value.
VALUES('Iran', 957)
In order for the INSERT INTO statement to actually be reflected in the database you have to call connection.commit() followed by connection.close(). Another similar thread describing this: Java General Error On Insert...???

how to resolve org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback;

I am using HSQLDB as my database. i want to get a primary key of latest inserted row. for that i have return a query in my java class as below:
final String query = "INSERT INTO polling_log (start_date,status,action) VALUES(CURRENT_TIMESTAMP,?,?); CALL IDENTITY();";
GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();
int update = adapterJdbcTemplate.update(new PreparedStatementCreator() {
#Override
public PreparedStatement createPreparedStatement(
Connection connection) throws SQLException {
PreparedStatement preparedStatement = connection
.prepareStatement(query);
preparedStatement.setInt(1, pollingLogVO.getStatus());
preparedStatement.setString(2, pollingLogVO.getAction());
System.out.println(preparedStatement.getGeneratedKeys().getFetchSize());
return preparedStatement;
}
}, generatedKeyHolder);
System.out.println("###################### "+ update);
Number logId = generatedKeyHolder.getKey();
pollingLogId = logId.intValue();
and to store the query i have used GeneratedKeyHolder. but while runing this i get an exception:
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar []; nested exception is java.sql.SQLException: unexpected token: IDENTITY
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:98)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:602)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:817)
at com.platysgroup.lmex.adapter.moodle.dao.LogDao.insertPollingLog(LogDao.java:36)
at com.platysgroup.lmex.adapter.MoodlePostingTask.insertPollingLog(MoodlePostingTask.java:134)
at com.platysgroup.lmex.adapter.MoodlePostingTask.run(MoodlePostingTask.java:55)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Caused by: java.sql.SQLException: unexpected token: IDENTITY
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:248)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:302)
at com.platysgroup.lmex.adapter.moodle.dao.LogDao$1.createPreparedStatement(LogDao.java:41)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:580)
... 6 more
Caused by: org.hsqldb.HsqlException: unexpected token: IDENTITY
at org.hsqldb.error.Error.parseError(Unknown Source)
at org.hsqldb.ParserBase.unexpectedToken(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)
... 12 more
The problem is with this line (wrapped for clarity):
final String query = "INSERT INTO polling_log (start_date,status,action) VALUES(CURRENT_TIMESTAMP,?,?); CALL IDENTITY();";
The issue is that IDENTITY is a reserved word in SQL; it's got a meaning pre-defined already and so can't be used like that in a CALL statement. (I don't know what it is actually used for; the full definition of SQL is huge and has a very large number of reserved words.) The immediate work around would be to enclose the problem word in double quotes (which would need to be backslash-quoted because of being in a Java string):
final String query = "INSERT INTO polling_log (start_date,status,action) VALUES(CURRENT_TIMESTAMP,?,?); CALL \"IDENTITY\"();";
However, if you're just calling that to get the inserted row, STOP! Just let Spring do the work for you, assuming you have JDBC 3.0 or later (i.e., Java 5 or later).
As far as I know you cannot put more than one statements into one string to be executed. Execute two separate operations instead of this.
The following link has what you need:
http://www.devdaily.com/blog/post/jdbc/spring-jdbc-insert-auto-generated-key