Spring data #Formula count query - java

I'm trying to use count query inside the #Formula (Spring boot app)
#Formula("select count(te.id) from task_execution te")
however when starting server, getting exception
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
says I have syntax error in query and following query printed in log:
select count(te.id) from task_execution te as formula6_ from node_info nodeinfo0
my question where this from node_info nodeinfo0 came from? My NodeInfo class is not related to TaskExecution class in any way
Thanks

So the solution was to put the expression into braces. The error was very misleading.

Related

Can't create proper spring data custom query using reference field as parameter

I'm trying to make custom spring Data query using field from reference as query
parameter. When i performed this query via REST i had no results at all:
I enabled hibernate logs and copy it to H2 console and I got many results:
My Flight and Airport entities are very simple
So what am I doing wrong? I have other simpler methods and they work fine using browser. I tried the same using Query annotation(second method on second screen), but I got same results. (Copied generated sql query to H2 console and received many results but it didn't work via REST).
EDIT
I found the solution. I just removed quotation marks from URL and
it works well :D
Sorry for my inattention.
Regards,
Michal
I found the solution. It was very simple. Basically I just removed quotation marks from URL and it works well :D
Actual method in Repository looks like:
List findFlightsByFromCityAndToCity(#Param("from") String from, #Param("to") String to);
Regards,
Michal

Hibernate - The column name att_id_1 is not valid

For some reason the query that is generated by hibernate is wrong. I have other tables/classes where the generated query is correct however for one table it is wrong. When I do a trace using MS Management Studio I see the following:
exec sp_prepexec #p1 output,NULL,N'select aprresourc0_.agrtid as agrtid1_14_, aprresourc0_.att_id_1 as att_id_2_14_,
aprresourc0_.att_id_2 as att_id_3_14_, aprresourc0_.att_id_3 as att_id_4_14_, aprresourc0_.att_id_4 as att_id_5_14_,
aprresourc0_.attribute_id as attribut6_14_, aprresourc0_.bflag as bflag7_14_, aprresourc0_.client as client8_14_, ...
from aprresourcepost aprresourc0_
where ...
select #p1
The columns att_id_1, att_id_2, att_id_3 and att_id_4 do not exist in the table or my Java class!
How do I fix this? Why does this happen?
It turns out to have been a simple mistake. I continued to work on the project and the next class I was looking at matched the query I was getting in my problem so I checked the code and found I was referencing the wrong class in my code!

Hibernate: column does not exist

When I try to load an Entity with Hibernate I get the following error in postgres-log:
ERROR: column appuser0_.device_token does not exist at character 35
STATEMENT: select appuser0_.id as id1_27_0_, appuser0_.device_token as device_t2_27_0_,....
The column device_token definitely exists - and if I copy-paste the whole logged statement and execute it in PGAdmin, I get the expected result.
So what do I forget? What is the difference between the Hibernate statement and the manually executed one?
This issue was caused by the multi tenant configuration so that the wrong DataSource has been chosen.
Depending on how you defined the query, the problem might be located somewhere else: For example, HQL Queries are using the "property-names" of the class, not the column names.
And if you have something like:
#Column("device_token")
private String deviceToken;
Then your HQL-Query should target "deviceToken" and not "device_token". We also encountered a similar error once: Hibernate was reporting "user_id" is missing, because we named the property "userId" with the underscored version for the column name only.
This might be not the problem for you but worth double checking it.

How do I perform a batch delete with the playframework / jpa?

I recently started falling in love with the play! framework but now I am confused about how to use the batch delete method on a Model.
My attempt looks like this:
Shift.delete("byDateAndRestaurant", day, rest);
This, however, does not work. play! just throws this back at me:
IllegalArgumentException occured : org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: byDateAndRestaurant near line 1, column 41 [delete from models.Shift where byDateAndRestaurant]
which is very confusing as this code works flawlessly:
Shift.find("byDateAndRestaurant", day, rest).fetch();
(Of course, I could just loop through the results of the find query and delete each instance. But I don't want to cause too many database interactions.)
So what kind of query/shortcut notation does the delete method accept?
Shift.delete("Date=? AND Restaurant=?", day, rest);
should work fine.

LPX-00607 for ora:contains in java but not sqlplus

I am trying to doing some SQL queries out of Oracle 11g and am having issues using ora:contains. I am using Spring's JDBC implementation and my code generates the sql statement:
select *
from view_name
where column_a = ?
and column_b = ?
and existsNode(xmltype(clob_column),
'record/name [ora:contains(text(), "name1") > 0]',
'xmlns:ora="http://xmlns.oralce.com/xdb"') = 1
I have removed the actual view / column names obviously, but when I copy that into sqlplus and substitute in random values, the select executes properly. When I try to run it in my DAO code I get this stack trace:
org.springframework.jdbc.UncatergorizedSQLException: PreparedStatementCallback;
uncatergorizedSQLException for SQL [the big select above]; SQL state [99999];
error code [31011];
ORA-31011: XML parsing failed.
ORA-19202: Error occured in XML processing
LPX-00607: Invalid reference: 'contains';nested exception is java.sql.SQLException:
ORA-31011: XML parsing failed
ORA-19202: Error occured in XML processing
LPX-00607: Invalid reference: 'contains'
(continues on like this for awhile....)
I think it is worth mentioning that I am using Maven and it is possible I am missing some dependency that is required for this. Sorry the post is so long, but I wanted to err on the side of too much info.
Thanks for taking the time to read this at least =)
-Windle
You appear to have a spelling mistake in your namespace declaration:
'xmlns:ora="http://xmlns.oralce.com/xdb"'
^^
If that really is a typo in your code (rather than just in your posting here) it can't hurt to fix it.

Categories