I am trying to use hsqldb-2.3.4 to connect from Spring applicastion.
I created data base using the following details
Type : HSQL Database Engine Standalone
Driver: org.hsqldb.jdbcDriver
URL: jdbc:hsqldb:file:mydb
UserName: SA
Password: SA
I created a table named ALBUM under "MYDB" schema
In spring configuration file:
<bean id="jdbcTemplate"
class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
<constructor-arg ref="dbcpDataSource" />
</bean>
<bean id="dbcpDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:file:mydb" />
<property name="username" value="SA" />
<property name="password" value="SA" />
</bean>
And in my spring controller I am doing jdbcTemplate.query("SELECT * FROM MYDB.ALBUM", new AlbumRowMapper());
And It gives me exception:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT * FROM MYDB.ALBUM]; nested exception is java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: ALBUM
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
If I execute same query through SQL editor of hsqldb it executes fine. Can you please help me with this.
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 mode
for 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"
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.
I had the error user lacks privilege or object not found while trying to create a table in an empty in-memory database.
I used spring.datasource.schema and the problem was that I missed a semicolon in my SQL file after the "CREATE TABLE"-Statement (which was followed by "CREATE INDEX").
I had similar issue with the error 'org.hsqldb.HsqlException: user lacks privilege or object not found: DAYS_BETWEEN' turned out DAYS_BETWEEN is not recognized by hsqldb as a function. use DATEDIFF instead.
DATEDIFF ( <datetime value expr 1>, <datetime value expr 2> )
When running a HSWLDB server. for example your java config file has:
hsql.jdbc.url = jdbc:hsqldb:hsql://localhost:9005/YOURDB;sql.enforce_strict_size=true;hsqldb.tx=mvcc
check to make sure that your set a server.dbname.#. for example my server.properties file:
server.database.0=eventsdb
server.dbname.0=eventsdb
server.port=9005
I was inserting the data in hsql db using following script
INSERT INTO Greeting (text) VALUES ("Hello World");
I was getting issue related to the Hello World object not found and HSQL database user lacks privilege or object not found error
which I changed into the below script
INSERT INTO Greeting (text) VALUES ('Hello World');
And now it is working fine.
Add these two extra properties:
spring.jpa.hibernate.naming.implicit-strategy=
org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=
org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
I bumped into kind of the same problem recently. We are running a grails application and someone inserted a SQL script into the BootStrap file (that's the entry point for grails). That script was supposed to be run only in the production environment, however because of bad logic it was running in test as well. So the error I got was:
User lacks privilege or object not found:
without any more clarification...
I just had to make sure the script was not run in the test environment and it fixed the problem for me, though it took me 3 hours to figure it out. I know it is very, very specific issue but still if I can save someone a couple of hours of code digging that would be great.
I was having the same mistake. In my case I was forgetting to put the apas in the strings.
I was doing String test = "inputTest";
The correct one is String test = "'inputTest'";
The error was occurring when I was trying to put something in the database
connection.createStatement.execute("INSERT INTO tableTest values(" + test +")";
In my case, just put the quotation marks ' to correct the error.
In my case the error occured because i did NOT put the TABLE_NAME into double quotes "TABLE_NAME" and had the oracle schema prefix.
Not working:
SELECT * FROM FOOSCHEMA.BAR_TABLE
Working:
SELECT * FROM "BAR_TABLE"
had this issue with concatenating variables in insert statement. this worked
// var1, var3, var4 are String variables
// var2 and var5 are Integer variables
result = statement.executeUpdate("INSERT INTO newTable VALUES ('"+var1+"',"+var2+",'"+var3+"','"+var4+"',"+var5 +")");
In my case the issue was caused by the absence (I'd commented it out by mistake) of the following line in persistence.xml:
<property name="hibernate.hbm2ddl.auto" value="update"/>
which prevented Hibernate from emitting the DDL to create the required schema elements...
(different Hibernate wrappers will have different mechanisms to specify properties; I'm using JPA here)
I had this error while trying to run my application without specifying the "Path" field in Intellij IDEA data source (database) properties. Everything else was configured correctly.
I was able to run scripts in IDEA database console and they executed correctly, but without giving a path to the IDEA, it was unable to identify where to connect, which caused errors.
You have to run the Database in server mode and connect.Otherwise it wont connect from external application and give error similar to user lacks privilege.
Also change the url of database in spring configuration file accordingly when running DB in server mode.
Sample command to run DB in server mode
$java -cp lib/hsqldb.jar org.hsqldb.server.Server --database.0 file:data/mydb --dbname.0 Test
Format of URL in configuration file
jdbc:hsqldb:hsql://localhost/Test
In my case, one of the columns had the name 'key' with the missing #Column(name = "key") annotation so that in the logs you could see the query that created the table but in fact it was not there. So be careful with column names
For what it's worth - I had this same problem. I had a column named 'TYPE', which I renamed to 'XTYPE' and a column named ORDER which I renamed to 'XORDER' and the problem went away.
Yet another reason could be a misspelt field name. If your actual table has an id column named albumid and you'd used album_id, then too this could occur.
As another anwer remarked, case differences in field names too need to be taken care of.
I faced the same issue and found there was more than one PersistenceUnit (ReadOnly and ReadWrite) , So the tables in HSQLDDB created using a schema from one persistence unit resulted in exception(HSQL database user lacks privilege or object not found error) being thrown when accessed from other persistence unit .It happens when tables are created from one session in JPA and accessed from another session
In my case the table MY_TABLE was in the schema SOME_SCHEMA. So calling select/insert etc. directly didn't work. To fix:
add file schema.sql to the resources folder
in this file add the line CREATE SCHEMA YOUR_SCHEMA_NAME;
Related
I am creating a job to pull data from a database to CSV file using talend open studio. There are 100 of tables, the data types and no of columns differ in the tables, I want to pull the data from database tables with a single job and customizable SQL query. I know how to create and use context variables.
If I understood you correctly you should be using tMap's reload at each row -option and defining table names in Excel sheet or in tFixedFlowInput.
tMap settings
Whole job and results
SQL Script:
"SELECT TOP(1) Name, Code from mdm." + (String)globalMap.get("row4.table")
I used Microsoft SQL Server for example but same script works as well with MySQL.
You can simply use a context-variable which you set via the --context_param argument in a tWhicheverDatabaseInput. E.g. define a context variable "my_sql" which you can set in the commandline as
my_job.sh --context_param my_sql="select a,b,c from a_test_table"
and then use context.my_sql as the SQL in you database input component.
However, as garpitmzn already mentioned, you will need dynamic schemas to actually work with this unknown structure in Talend. This feature only exists in the enterprise version.
If the enterprise version is available to you, simply declare a single column of type "Dynamic", which you can pass through the rest of your flow.
Declare a local context say query as type string.
Prepare a context file with variable query: query=select name from employee
Excecute the query: toraclecomponent use context.query
Query is throwing some error when you have where conditions with string type.
Need to investigate more on that. Otherwise it works.
storing filedata via a hibernate (using postgresql or oracle 10g/11g) property mapped as
<property name="fileData" type="binary">
<column name="fileData" length="104857600" />
</property>
from a java application i need to access the length of the field from the db (i do not want to load whole the object, for performance reasons). i did not find any hibernate (hql) solution to query that information, so i decided to search for features of the different databases that were used. for postgresql i found:
select BIT_LENGTH(filedata) from table
which works perfectly (and astonishing fast). now i need something similar for the use with oracle. i already tried
select utl_raw.length(filedata) from table
and
select DBMS_LOB.GETLENGTH(filedata) from table
which both results in the error msg:
"Error: ORA-00997: illegal use of LONG datatype"
is there any possibilty to query the length of that hibernate property on an oracle db without selecting the object itself?
(hibernate creates a "long raw" field on oracle, and a "bytea" field on postgresql)
thx in advance
(addition: statement will be used in a migration-context, newly created filedata entities will get a filesize property programatically)
Well, looks like i found an answer here:
https://community.oracle.com/thread/2137593
create table temp_deleteme as select to_lob(<long raw field>) obj from <tablename>;
select dbms_lob.getlength(obj) from temp_deleteme;
after creating the tempTable i can select the filedatalength from it, write it to my entities, and delete the table again. still not really good performance, but that let the db do the work and i will not have to transfer entities to my server for only calculating the needed information.
I am currently learning JPA with Hibernate, using maven as well.
It happens so that I need to use named query's in my orm.xml with a input parameter in the set-clausule of an update statement. It gives me an error that a parameter can only be used in the WHERE or HAVING clausule.
After reading several pages I found out that JPA 2.0 does not support it, but JPA 2.1 does.
See this, bulletpoint 4.6.4
So I changed my orm.xml and persistence.xml to the 2.1 schemes as well, but it still gives and error. Although it still runs perfectly, I hate seeing error signs.
Anyone Any idea? I am using Eclipse Kepler 4.3.2
Pictures of orm.xml, persistence.xml, pom.xml and my project properties can be found here
I have the same problem, code works fine and it should with JPA 2.1 (Final Release)
http://download.oracle.com/otn-pub/jcp/persistence-2_1-fr-eval-spec/JavaPersistence.pdf In chapter4.6.4 (page 182) find this text (my highlight):
"Input parameters can only be used in the WHERE clause or HAVING clause of a query or as the new value for an update item in the SET clause of an update statement. "
But eclipse validation still take input parameter in update query as an error...
Maybe we should raise a bug against org.eclipse.persistence.jpa.jpql
The following query should work:
<named-query name = "Artikel.findByWord">
<query>
UPDATE Artikel a
SET a.verkoopprijs = a.verkoopprijs * :percentage
</query>
</named-query>
with the corresponding java code:
em.createNamedQuery("Artikel.findByWord")
.setParameter("percentage", 10)
.executeUpdate();
When doing...
select * from students
I get a "Invalid object name" error. Basically, I think I can see the problem in that the tables are prefixed with an object name rather than just dbo, lets call the schema "test".
So this means....
select * from test.students
The problem I have is that I can't change the SQL code (it's in release, long story) or change the tables. My question is, is there anything I can change in SQL server that will allow me to connect say with a specific SQL server user so I can still run my queries as...
select * from students
Omitting the object name, but still have the object name against the table? I can add another SQL user or something like that no problem.
I'm using Java over the jdbc protocol, so my connection string is something like jdbc:sqlserver://hostname:port;databaseName=db;user=myuser;password=mypassword
Thanks,
David
You're looking for a default schema option, which doesn't exist for a given connection. That is to say that you can't say something like "until I say otherwise, unqualified tables are in the test schema". You can, however, set a default schema for a user. For your example, you'd do
alter user [myuser] with default_schema = [test]
Try to edit the connection string and set your default catalog to your "test" database
<add name="ConnectionString" connectionString="Data Source=server;Initial
Catalog=test;Persist Security Info=True;User ID=user;Password=password;"
providerName="SqlDataClient"/>
SEVERE: Local Exception Stack:
Exception [EclipseLink-7092] (Eclipse Persistence Services - 2.0.0.v20091127-r5931):
org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot add a query whose types conflict with an existing query.
Query To Be Added: [ReadAllQuery(name="Voter.findAll" referenceClass=Voter
jpql="SELECT v FROM Voter v")] is named: [Voter.findAll] with arguments [[]].
The existing conflicting query: [ReadAllQuery(name="Voter.findAll" referenceClass=
Voter jpql="SELECT v FROM Voter v")] is named: [Voter.findAll] with arguments: [[]].
I too have come across this issue and it makes little sense. I only have one entity bean with one defined query, and it continues to tell me it's the problem. I did a stop, then start of GF3, redploy my app, and I still get it.. and worse, I am not even using the query.
One thing I don't understand.. why is EclipseLink being used in GF? Is that part of GF? I use Eclipse IDE, but I don't deploy from within Eclipse.. I deploy from my ant build script at command line. I am guessing GF must be using some EclipseLink (used to be TopLink?).
One answer above said to make sure there are no stale files, undeploy app, etc. Would be great if someone that has figured this out could provide more details and explain it. If it is another query that has an error in it, sure would be nice if the error was shown instead of this misleading one.
So far, I've stopped GF, dropped all the tables, restarted, redeployed (in autodeploy folder), and still get this issue right away. I generally build/deploy to autodeploy folder several times in short periods of time, as I make quick changes then build/redeploy.
I encountered this problem also, I found out the exception isn't related with the error file at all, the problem is from another query for example:
#NamedQuery(name = "ChannelType.ALL", query = "SELECT channelType FROM ChannelType channelType WHERE channelType.applicationClient.applicationClientId =:applicationClientId ORDER BY channelType.channelTypId ASC")
the problem is from "ORDER BY channelType.channelTypId" its not except to order by primary key ,when I remove this line the exception just gone also.
Maybe someone else could explain why this happen.
Thanks
Just for the people out there that are still struggling with this error:
Undeploy your application and check if there are any stale (maybe locked) files left. This would cause the old namedqueries to still exist and thus not replacing them.
Delete the files and redeploy. The error should disappear.
Edit:
Also check if you haven't done anything like ... WHERE o.object_id = :id ... instead of ... WHERE o.object = :object ...
This was the solution for my problems. Took me 3 weeks to figure that out. EclipseLink isn't very clear when it comes to exceptions. There was actually a query compile error. Instead it throws a duplicate query exception.
It looks like you have the query defined twice. Either on the same entity, or on another entity, or in orm.xml
Not sure of what you're doing exactly since you're not showing any code but this is what EclipseLink documentation says about error ECLIPSELINK-07092:
ECLIPSELINK-07092: Cannot add a query whose types conflict with an
existing query. Query To Be Added:
[{0}] is named: [{1}] with arguments
[{2}].The existing conflicting query:
[{3}] is named: [{4}] with arguments:
[{5}].
Cause: EclipseLink has detected a conflict between a custom
query with the same name and arguments
to a session.
Action: Ensure that no query is added to the session more than once
or change the query name so that the
query can be distinguished from
others.
According to the above description and to the trace, it seems that you're adding a query (actually the same) with the same query name more than once to the session. You shouldn't (or use another query name).
also the error can come from a namedquery malformed, i had an where y o.activo -> that show me the specified error.
I had the problem...
The real Exception was a #Named Query malformed but the stacktrace just said:
"Exception Description: Cannot add a query whose types conflict with
an existing query"
My solution:
In the persistence unit change Table Generation Strategy to "None" and Validation Strategy to "None". When run again I obtained the real Exception (Malformed Query). I resolved the error in the query, returned to the old configuration in the persistence unit and all exceptions disappeared.
I'm going crazy but at least, this not works:
#NamedQuery(name = "xyx", query = "SELECT count(v) FROM Classe v WHERE v.id =:_id);
this works:
#NamedQuery(name = "xyx", query = "SELECT count(v) FROM Classe v WHERE v.id = :_id);
"WHERE v.id =:_id" was the error