Hibernate SQL - Can't get an interval from table - java

I'm trying to get an interval through an operation with Timestamps from a table but I'm getting a "No Dialect mapping for JDBC type: 1111"
The code is like this:
SELECT TS_FINISH - TS_START FROM TABLE
Where TS_FINISH and TS_START are Timestamps

I used a function from my DBMS to cast the result to a text.
Unfortunately there is no hql function that does it.

Related

Sybase DataContext : The column prefix does not match with a table name or alias name

We are dealing with sybase database in core java code. We are using org.eobjects.metamodel.DataContext to parse query.
String sCol[]=table.getColumnNames();
Query query=dataContext.query().from(table.getName()).select(sCol).toQuery();
return new QueryIterator(dataContext.executeQuery(query).iterator());
But it executing query. Same code working fine with Oracle database to parse and execute query.
Some of query example generated are :
select City.CityName from ownername.City
select City.CityName from City
select CityName from ownername.City
select CityName from City
select ownername.City.CityName from ownername.City
SELECT "City"."CityName" FROM ownername."City"
select * from ownername.City
No any of above query executed. We are getting these errors :
Not capable of parsing FROM token: "ownername"."City"
Could not execute query: The column prefix '"City"' does not match with a table name or alias name used in the query. Either the table is not specified in the FROM clause or it has a correlation name which must be used instead.
Not capable of parsing SELECT token: ownername.City.CityName
How can we execute query using metamodel wih SYBASE database OR is there any other way to execute sybase queries?
Oracle (and Microsoft) use a schema logical construct that Sybase ASE does not. In SAP/Sybase ASE, all tables and columns in a database are in the same schema. It is possible to users to have their own objects in the database though, so there is the possibility of imitating some of the schema behavior using user ownership, but it would require an extra level of effort.
For Sybase the proper query syntax would be:
SELECT [ Col1, Col2 | * ]
FROM [dbName].[ownerName.]TABLE
In your case
SELECT CityName
FROM dbName.ownername.City
In Sybase ASE, it's typically best practice to have all objects owned by 'dbo', so in that case you can omit the owner from the query:
SELECT CityName
FROM dbName..City
Full query syntax and information can be found in the Query Section of the Transact SQL Users Guide in the documentation.
The error messages you're getting are coming from MetaModel's query parser layer. It is searching for matching column and table names in the metadata of your database before it's even firing the query.
I notice that you're using namespace "org.eobjects.metamodel". You should upgrade to Apache MetaModel ("org.apache.metamodel") if possible since a lot has been improved in MetaModel since it's introduction into Apache. Including a lot of query parser improvements.

Insert map and other complex types in hive using jdbc

I have a java Map (Map) and a JDBC connection to hive server.
The schema of the table at the server contains a column of type Map.
Is it possible to insert the java Map to the hive table column with similar datatype using JDBC?
I tried:
"create table test(key string, value Map<String, String>)"
"insert into table test values ('keywer', map('subkey', 'subvalue')) from dummy limit 1;"
ref: Hive inserting values to an array complex type column
but the insert failed with:
"Error: Error while compiling statement: FAILED: ParseException line 1:69 missing EOF at 'from' near ')' (state=42000,code=40000)"
[EDIT]
hive version is : 0.14.0
Thanks
The manual clearly says you cannot insert into a Map data type using SQL:
"Hive does not support literals for complex types (array, map, struct, union), so it is not possible to use them in INSERT INTO...VALUES clauses. This means that the user cannot insert data into a complex datatype column using the INSERT INTO...VALUES clause.”
I think the correct DDL and query would be:
CREATE TABLE test(key STRING, value MAP<STRING, STRING>);
INSERT INTO TABLE test VALUES('keywer', map('subkey', 'subvalue')) from dummy limit 1;
A working method to put a complex type from jdbc client is:
insert into table test select "key",map("key1","value1","key2","value2") from dummy limit 1;
where dummy is another table which has at least one row.

Query with WHERE clause on timestamp does not return results on one table but fine on the other

I have 2 tables A and B with reporting_date_time as timestamp(6).
When I query table A executes fine but not on table B
This is my query:
select * from A where reporting_date_time = ?
I use JDBC PreparedStatements and pass the argument through: prepStmt.setTimestamp(1, myTimestampVar);.
private java.sql.Timestamp myTimestampVar;
myTimestampVar.toString shows the value as '2014-11-26 00:00:00.0'
Strange thing is that same application gets data from both tables in user testing, while it fails to do so in production even though it is the same JDBC driver on both environments.
I got oracle trace enabled and found that in table A timestamp is passed to the query as 26-NOV-14 12.00.00 AM, while that in table B it is passed as 26-NOV-14 00.00.00.
Why would it is sending it in two different formats?

JDBC query doesn't work when giving NamedParameterJdbcOperation gets date as parameter (in params map)

I try to query my Mysql DB using JDBC.
I use the org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations.
The column DATE_FROM in my_table is defined as DATE column (which is also a PK).
A simplified version of a query which works looks like this:
SELECT * FROM my_table WHERE DATE_FROM >='2015-03-01';
But then, I tried to change the the '2015-03-01' to be given as a named parameter. the query looked like this:
SELECT * FROM my_table WHERE DATE_FROM >=:fromDate;
while I invoked the NamedParameterJdbcOperations.update() like this:
map.put("fromTime", '2015-03-01');
namedParameterJdbcOperations.update(sql, map);
Although everything, to my understanding, remains the same, I get:
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: ''2015-03-01'' for column 'MEASUREMENT_DATE' at row 1.
Does someone know why?
Did you realize that you named the placeholder in the SQL "fromDate" and in the map, you named it "fromTime"?

No Dialect mapping for JDBC type: -102

i have a problem. Some sql in my program could be written by the user. So I don't know which table or which columns are in this sql. Therefore i want to detect which column names are in the sql. But if a date is in the sql i get the No Dialect mapping for JDBC type: -102 error.
How could i handle that? I am using hibernate 3.6 or 4.1.3 with java. My database is an oracle database. The dialect is org.hibernate.dialect.Oracle10gDialect.
I really don't know what is in the sql.
Here is my code:
SQLQuery q=session.createSQLQuery("SELECT * FROM tbl WHERE id = 2");
q.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);
List<Map<String,Object>> aliasToValueMapList=q.list();
for(Map<String,Object> map : aliasToValueMapList){
System.out.println(map.keySet());
break;
}
I hope anyone knows a solution for this problem.
Greetz
Your query is attempt to return a column that the JDBC ResultSetMetaData is reporting a type (-102) which Hibernate does not know how to read. You need to register the type for that column with the query using org.hibernate.SQLQuery#addScalar or you may not be able to use that transformer and actually define the entire result set mapping to your entity org.hibernate.SQLQuery#addRoot/org.hibernate.SQLQuery#addEntity. See the docs for usage
If you use session.createQuery() this will use your dialect to talk to the database using Hibernate Query Language. but if you use createSQLQuery() you have to use PL/SQL to talk to the oracle.

Categories

Resources