The query, created by myBatis, falls with the cause ORA-00933, "SQL command not properly ended".
All advice that I found on the net, says that there is some error in the SQL syntax. On the other hand, if I make the SQL by hand, Oracle SQL developer takes it as a correct one.
Obviously, I am making it by hand differently that myBatis does. And I need to check it. But how can I check the SQL query really sent by myBatis to the DB?
The MyBatis version used: 3.0
I am interested much more in the possibility to look for problems myself than to look for help with every problem. But some people here think that the question must contain the code, so here it is. (mapper.xml)
<sql id="pracovisteSql">
/* pozor, pracuje pouze do max 3 vrstev v cis_pracovist */
cis_pracoviste A
join cis_pracoviste B
on (A.stupen_rizeni in (0,1) and B.kod_nadrizeneho = A.kod_pracoviste) or
(A.stupen_rizeni = 2 and A.kod_pracoviste = B.kod_pracoviste)
join cis_pracoviste C
on (B.stupen_rizeni = 1 and C.kod_nadrizeneho = B.kod_pracoviste) or
(B.stupen_rizeni = 2 and C.kod_pracoviste = B.kod_pracoviste)
</sql>
<sql id="organizaceSql">
WITH organizace
AS (
SELECT a.kod_pracoviste as AKP, a.nazev as ANZ, a.stupen_rizeni as AST, a.kod_nadrizeneho as ANR,
b.kod_pracoviste as BKP, b.nazev as BNZ, b.stupen_rizeni as BST, b.kod_nadrizeneho as BNR,
c.kod_pracoviste as CKP, c.nazev as CNZ, c.stupen_rizeni as CST, c.kod_nadrizeneho as CNR
from
<include refid="pracovisteSql"/>
)
</sql>
<sql id="zahajeniOdDo">
(r01.dat_zahajeni between to_date(#{mesicRokOd}, 'MMYYYY') and to_date(#{mesicRokDo, 'MMYYYY'))
</sql>
<select id="getReportSR02Sql1"
parameterType="amcssz.spr.srv.main.dto.reports.ReportSR02QueryDTO"
resultType="amcssz.spr.srv.main.dto.reports.ReportSR02Sql1DTO">
<include refid="organizaceSql"/>
SELECT Count(Distinct (r01.id_r01_rizeni)) as pocetVRSP
From organizace
Left join r01_rizeni r01
on organizace.ckp = r01.kod_pracoviste and
r01.je_stornovano = 0 and
<include refid="zahajeniOdDo"/> and
r01.kod_skup_rizeni = 'VRSP' /* r01.kod_rizeni in ('VRSPUC', 'VRSPSR', 'VRSPPE', 'VRSPJI') */
Join r02_stavrizeni r02
on R01.ID_R01_RIZENI = R02.ID_R01_RIZENI and /* Změna 17.1.2020 */
R02.JE_AKTUALNI = '1' and
R02.KOD_STAV_RIZENI != 'STR'
Join r08_ukon r08
on R01.ID_R01_RIZENI = R08.ID_R01_RIZENI and /* Změna 17.1.2020 */
R08.KOD_UKON IN ('1','14','23','32') and
R08.JE_STORNOVAN = '0'
Join d02_obalka d02
on R08.ID_R08_UKON = D02.ID_R08_UKON and
d02.dat_doruceni IS NOT NULL
Where organizace.AKP = #{kodPracoviste} and
r01.kod_skup_rizeni is Not Null
Group by r01.kod_skup_rizeni
Order by 1;
</select>
You can configure your log4j level to show the mybatis logging like log4j.logger.org.mybatis.example=DEBUG
Full documentation will be found here
If you use intellij idea, try to add a plugin mybatis-log-plugin.The executed SQL will be output in the console
Related
Hi guys I have a problem with SPEL - Flexible Search, this is my error log when into my entity I click on button search:
ERROR [hybrisHTTP6] [PagingDelegateController] cannot search unknown field 'TableField(name='inStockStatus',langPK='null',type=Product)' within type Product unless you disable checking
and this is the query that I must create :
select {p.code},{p.description},{bs.uid}, (CASE WHEN ({p.onlineDate} is not null AND {p.onlineDate} > current_timestamp ) THEN 1 else 0 END)
from {Product as p join StockLevel as s on {s.productCode} = {p.code} join BaseStore2WarehouseRel as b on {b.target} = {s.warehouse} join BaseStore as bs on {bs.pk} = {b.source}}
where {bs.uid} in ('baseStorePk')
and {p.code} = '?productCode'
and {p.description} = '?description'
and {p.descriptionCics} = '?descriptionCics'
and {p.onlinedate} <= '?onlineDateFrom'
and {p.onlinedate} >= '?onlineDateTo'
and {s.inStockStatus} = '?inStockStatus'
and {p.doneBy} = '?doneBy'
and {s.outOfStockCause} = '?oosCause'
and {p.department} = '?department'
and {p.grm} = '?grm'
and in the image the report that I have create into myExtension-items-core.xml
based on Exception it's clear you are referring wrong attribute of product is "inStockStatus".
please replace with {s.inStockStatus} instead of {p.inStockStatus}
I'm using Java 11 and Postgres 9.6. I am writing a SQL query that will be included in my Java application and I will pass in values to the variables designated with a:
SQL
CASE
WHEN (:designatorInclude IS NOT NULL)
THEN totdl.designator_id IN (:designatorInclude)
ELSE ttl.product_code IS NOT NULL
END
Java
String filterProductCodes = IOUtil.readResourceText(MyService.class, "sql_files/FilterProductCodes.sql");
Query filterProductCodesQuery = this.em.createNativeQuery(filterProductCodes)
if(inDto.getIdList() != null)
{
filterProductCodesQuery.setParameter("designatorInclude", inDto.getIdList);
}else{
filterProductCodesQuery.setParameter("designatorInclude", null);
}
Passing variables in like this works in many other places in the application. The difference here is that I'm using a CASE/WHERE statement.
Everything compiles fine, but when I try to hit this part of the code, I get the following error:
PSQLException: ERROR: argument of CASE/WHEN must be type boolean, not type record
I found 1 post on the internet about this and it did not apply to my situation.
Can anyone shed some light on this? Any suggestions on how I can get this to work?
Full SQL - case statement is towards the end.
SELECT DISTINCT ttl.product_code,
si.condition,
totdl.designator_id,
ttl.active as ttl_active,
l.active as l_active,
ii.mls_order_id,
ii.damaged,
ttl.id as ttl_id,
ll.location_id as ll_locationId,
cl.location_id as cl_locationId
FROM serial_item si
JOIN inventory_item ii ON ii.id = si.id
AND ii.mls_order_id IS NULL
AND ii.damaged = false
JOIN title ttl ON ttl.id = si.title_id
AND ttl.active = true
JOIN public.title_owner_title_designator_lookup totdl ON ttl.id = totdl.title_id
JOIN locator l ON l.id = ii.locator_id
AND l.active = true
LEFT JOIN location_locator ll ON ll.id = l.id
AND ll.status IN ('Shelf', 'Intake', 'Donation', 'Wholesaler')
LEFT JOIN course_locator cl ON cl.id = l.id
WHERE COALESCE(ll.location_id, cl.location_id) = :locationId
AND ll.do_not_list_on_markets = false
AND CASE
WHEN (:designatorInclude IS NOT NULL)
THEN totdl.designator_id IN (:designatorInclude)
ELSE ttl.product_code IS NOT NULL
END
I got this to work by changing my IS NOT NULL check to a COALESCE
CASE
WHEN **(COALESCE(:include, 0) != 0)**
THEN totdl.designator_id IN (:include)
ELSE ttl.product_code IS NOT NULL
If I would you, I would select just row column such
SELECT ttl.product_code, totdl.designator_id
FROM ...
I mapped this query normal to an Bean or Entity.
And an transient getter could solve your problem.
I am creating web-app which will be used to database managament. Now i am trying to implement "sql interpreter" and after input some incorrect queries i need to print sql errors. Here is my code:
public String executeSQL(String[] split){
SessionFactory hibernateFactory = someService.getHibernateFactory();
Session session = hibernateFactory.openSession();
String feedback= null;
for (int i = 0; i < split.length; i++) {
try{
String query = split[i];
session.doWork(connection -> connection.prepareStatement(query).execute());
feedback= "Success";
}
catch(Exception e){
feedback= ((SQLGrammarException) e).getSQLException().getMessage();
}
}
session.close();
return feedback;
}
My question:
Is there any way to get "positive message"? I mean: if i will do for example: 'insert into table' i want message:
"1 rows affected"
You know what i mean, i want that information from sql compiler:
You can use my open source program plsql_lexer to generate information about the success of an operation. The program imitates the feedback messages produced by SQL*Plus. The program handles all documented (and some undocumented) command types. The downside is that it must be installed on the database and requires a separate call to the database.
For example, after installing the program (which is mostly just download and run "#install"), create a simple function like this:
create or replace function get_success_message
(
p_statement clob,
p_number_of_rows number
) return varchar2 is
v_success_message varchar2(4000);
v_ignore varchar2(4000);
begin
--Get the feedback message.
statement_feedback.get_feedback_message(
p_tokens => plsql_lexer.lex(p_statement),
p_rowcount => p_number_of_rows,
p_success_message => v_success_message,
p_compile_warning_message => v_ignore
);
return v_success_message;
end;
/
Now you can generate feedback messages by calling the function, like this:
select
get_success_message('insert into test1 values(1)', 1) insert_1,
get_success_message('insert into test1 values(1)', 0) insert_0,
get_success_message('delete from test1', 50) delete_50
from dual;
INSERT_1 INSERT_0 DELETE_50
-------------- --------------- ----------------
1 row created. 0 rows created. 50 rows deleted.
The program was built to create database-centric, private SQL Fiddles, and may help with other tasks related to running arbitrary database commands.
I am trying to retrieve a long set of result and in doing so I find that the result data is being truncated automatically. I also noticed that the limit of result(String) is 1024 characters. How can I avoid this to get whole data?
I am accessing tables through JDBC, if that matters.
Code:-
SELECT OLL.EMAIL_ID,COUNT(1) AS TOTAL_ORDERS,OLL.SHIPPING_NAME ,SUM(OFF.UNIT_PRICE*OFF.QUANTITY) AS TOTAL_GMV,
MIN(ODD.CREATION_DATE) AS FIRST_PURCHASE,MAX(ODD.CREATION_DATE) AS LAST_PURCHASE,GROUP_CONCAT(OFF.PAYMENT_MODE) AS PAY_MODES,
GROUP_CONCAT(OFLL.PRODUCT_ID)AS PRODUCT_IDS,LEFT(GROUP_CONCAT(OFLL.PRODUCT_NAME),2048) AS PRODUCTS,OLL.BRAND_NAME,GROUP_CONCAT(OFF.GCTYPE) AS GCTYPE,
OLL.SHIPPING_CITY,OLL.SHIPPING_STATE,GROUP_CONCAT(OFF.UNIT_PRICE-OFF.UNIT_SHIPPING_PRICE) AS PRODUCT_PRICE,GROUP_CONCAT(CEILING(OFF.QUANTITY*OFF.UNIT_PRICE)) AS PRODUCT_GMV,GROUP_CONCAT(OFLL.CHANNEL) AS SALES_CHANNEL
FROM (
SELECT COUNT(1), OL.ORDER_ID, OL.EMAIL_ID, OFL.CREATED_BY,OL.SELLER_CITY,OL.SHIPPING_STATE
FROM (SELECT CREATION_DATE,ORDER_ID,ORDER_ITEM_SEQ_ID FROM ORDER_DATES WHERE CREATION_DATE
BETWEEN '2015-01-30 23:55:00' AND '2015-01-30 23:59:59') OD
INNER JOIN ORDER_LOGISTICS OL ON OD.ORDER_ID = OL.ORDER_ID AND OD.ORDER_ITEM_SEQ_ID = OL.ORDER_ITEM_SEQ_ID
INNER JOIN ORDER_FINANCE OF ON OL.ORDER_ID = OF.ORDER_ID AND OL.ORDER_ITEM_SEQ_ID = OF.ORDER_ITEM_SEQ_ID
INNER JOIN ORDER_FILTERS OFL ON OL.ORDER_ID = OFL.ORDER_ID AND OL.ORDER_ITEM_SEQ_ID = OFL.ORDER_ITEM_SEQ_ID
INNER JOIN ORDER_STATUS OS ON OL.ORDER_ID = OS.ORDER_ID AND OL.ORDER_ITEM_SEQ_ID = OS.ORDER_ITEM_SEQ_ID
WHERE (OF.PAYMENT_MODE='Cash On Delivery' OR OS.PAYMENT_STATUS='Received')AND (OFL.PRODUCT_ID IN ('B4333897','B5163012','B5654542') OR OF.UNIT_PRICE-OF.UNIT_SHIPPING_PRICE='1.00') AND
OFL.CHANNEL IN ('Web Channel', 'Mobile Web Channel') AND
OL.EMAIL_ID IS NOT NULL GROUP BY OL.EMAIL_ID) AAA, ORDER_LOGISTICS OLL, ORDER_FILTERS OFLL,
ORDER_FINANCE OFF,ORDER_DATES ODD WHERE AAA.EMAIL_ID=OLL.EMAIL_ID AND
OLL.ORDER_ID=OFLL.ORDER_ID AND OLL.ORDER_ITEM_SEQ_ID=OFLL.ORDER_ITEM_SEQ_ID AND (OFLL.PRODUCT_ID IN ('B4333897','B5163012','B5654542') OR OFF.UNIT_PRICE-OFF.UNIT_SHIPPING_PRICE='1.00') AND
OFLL.ORDER_ID=ODD.ORDER_ID AND OFF.ORDER_ID=OLL.ORDER_ID AND OFF.ORDER_ITEM_SEQ_ID=OLL.ORDER_ITEM_SEQ_ID
GROUP BY OLL.EMAIL_ID
Since I am using GROUP_CONCAT(), the result comes out to be lengthy and that's where it gets truncated.
I'm trying to improve performance of my HQL query, and I'm stumped. My OneToOne associations on the Adjuster, ZipCode, and EagleUsers objects are all marked as FetchType.LAZY, but nonetheless they're getting immediately pulled from the database when I use this query.
session.createQuery(
"FROM Adjuster a, ZipCode z, EagleUsers e WHERE a.eagleUsersByUserId = e.userId AND a.adjusterContact.zipCode = z.zip AND a.active = true AND a.isRecordDeleted = false"
).setMaxResults(1).list();
Why is it doing that?
SQL Output:
Hibernate: select top 1 adjuster0_.AdjusterId as Adjuster1_2_0_, zipcode1_.ZipId as ZipId1_163_1_, eagleusers2_.UserId as UserId1_91_2_, adjuster0_.Active as Active2_2_0_, adjuster0_.AutoAssign as AutoAssi3_2_0_, adjuster0_.SupervisorId as Supervis6_2_0_, adjuster0_.UserId as UserId7_2_0_, adjuster0_.IsRecordDeleted as IsRecord4_2_0_, adjuster0_.IsW2 as IsW5_2_0_, zipcode1_.Areacode as Areacode2_163_1_, zipcode1_.City as City3_163_1_, zipcode1_.County as County4_163_1_, zipcode1_.DST as DST5_163_1_, zipcode1_.Latitude as Latitude6_163_1_, zipcode1_.Longitude as Longitud7_163_1_, zipcode1_.State as State8_163_1_, zipcode1_.Timezone as Timezone9_163_1_, zipcode1_.TimezoneOffset as Timezon10_163_1_, zipcode1_.Zip as Zip11_163_1_, eagleusers2_.FirstName as FirstNam2_91_2_, eagleusers2_.IsRecordDeleted as IsRecord3_91_2_, eagleusers2_.LastName as LastName4_91_2_, eagleusers2_.SubRoleId as SubRoleI5_91_2_ from eagle_prd.dbo.Adjuster adjuster0_ cross join eagle_prd.dbo.ZipCode zipcode1_ cross join eagle_prd.dbo.EagleUsers eagleusers2_ cross join eagle_prd.dbo.AdjusterContact adjusterco3_ where adjuster0_.AdjusterId=adjusterco3_.AdjusterId and adjuster0_.UserId=eagleusers2_.UserId and adjusterco3_.ZipCode=zipcode1_.Zip and adjuster0_.Active=1 and adjuster0_.IsRecordDeleted=0
Hibernate: select adjusterau0_.AdjusterId as Adjuster1_3_0_, adjusterau0_.CurrentWorkZipCode as CurrentW2_3_0_, adjusterau0_.ExcludeHomeZip as ExcludeH3_3_0_, adjusterau0_.HomeZipCode1 as HomeZipC4_3_0_, adjusterau0_.HomeZipCode2 as HomeZipC5_3_0_, adjusterau0_.IsRecordDeleted as IsRecord6_3_0_, adjusterau0_.MaxOneDayClaims as MaxOneDa7_3_0_, adjusterau0_.MaxOneWeekClaims as MaxOneWe8_3_0_, adjusterau0_.MaxTwoDayClaims as MaxTwoDa9_3_0_, adjusterau0_.VacationEnd as Vacatio10_3_0_, adjusterau0_.VacationStart as Vacatio11_3_0_, adjusterau0_.WebAssignments as WebAssi12_3_0_ from eagle_prd.dbo.AdjusterAutoAssign adjusterau0_ where adjusterau0_.AdjusterId=?
Hibernate: select adjusterco0_.AdjusterId as Adjuster1_7_0_, adjusterco0_.CarAllowance as CarAllow2_7_0_, adjusterco0_.IsRecordDeleted as IsRecord3_7_0_, adjusterco0_.PhoneAllowance as PhoneAll4_7_0_, adjusterco0_.PhotoPercentage as PhotoPer5_7_0_, adjusterco0_.SeviceFeePercentage as SeviceFe6_7_0_ from eagle_prd.dbo.AdjusterCompensation adjusterco0_ where adjusterco0_.AdjusterId=?
Hibernate: select adjusterco0_.AdjusterId as Adjuster1_8_0_, adjusterco0_.City as City2_8_0_, adjusterco0_.Fax as Fax3_8_0_, adjusterco0_.IsRecordDeleted as IsRecord4_8_0_, adjusterco0_.Mobile as Mobile5_8_0_, adjusterco0_.Phone as Phone6_8_0_, adjusterco0_.PhoneExt as PhoneExt7_8_0_, adjusterco0_.State as State8_8_0_, adjusterco0_.Street1 as Street9_8_0_, adjusterco0_.Street2 as Street10_8_0_, adjusterco0_.ZipCode as ZipCode11_8_0_ from eagle_prd.dbo.AdjusterContact adjusterco0_ where adjusterco0_.AdjusterId=?
Hibernate: select aspnetuser0_.UserId as UserId1_171_0_, aspnetuser0_.ApplicationId as Applicat7_171_0_, aspnetuser0_.IsAnonymous as IsAnonym2_171_0_, aspnetuser0_.LastActivityDate as LastActi3_171_0_, aspnetuser0_.LoweredUserName as LoweredU4_171_0_, aspnetuser0_.MobileAlias as MobileAl5_171_0_, aspnetuser0_.UserName as UserName6_171_0_ from eagle_prd.dbo.aspnet_Users aspnetuser0_ where aspnetuser0_.UserId=?
Hibernate: select aspnetmemb0_.UserId as UserId1_167_0_, aspnetmemb0_.ApplicationId as Applica21_167_0_, aspnetmemb0_.Comment as Comment2_167_0_, aspnetmemb0_.CreateDate as CreateDa3_167_0_, aspnetmemb0_.Email as Email4_167_0_, aspnetmemb0_.FailedPasswordAnswerAttemptCount as FailedPa5_167_0_, aspnetmemb0_.FailedPasswordAnswerAttemptWindowStart as FailedPa6_167_0_, aspnetmemb0_.FailedPasswordAttemptCount as FailedPa7_167_0_, aspnetmemb0_.FailedPasswordAttemptWindowStart as FailedPa8_167_0_, aspnetmemb0_.IsApproved as IsApprov9_167_0_, aspnetmemb0_.IsLockedOut as IsLocke10_167_0_, aspnetmemb0_.LastLockoutDate as LastLoc11_167_0_, aspnetmemb0_.LastLoginDate as LastLog12_167_0_, aspnetmemb0_.LastPasswordChangedDate as LastPas13_167_0_, aspnetmemb0_.LoweredEmail as Lowered14_167_0_, aspnetmemb0_.MobilePIN as MobileP15_167_0_, aspnetmemb0_.Password as Passwor16_167_0_, aspnetmemb0_.PasswordAnswer as Passwor17_167_0_, aspnetmemb0_.PasswordFormat as Passwor18_167_0_, aspnetmemb0_.PasswordQuestion as Passwor19_167_0_, aspnetmemb0_.PasswordSalt as Passwor20_167_0_ from eagle_prd.dbo.aspnet_Membership aspnetmemb0_ where aspnetmemb0_.UserId=?
Hibernate: select aspnetprof0_.UserId as UserId1_168_0_, aspnetprof0_.LastUpdatedDate as LastUpda2_168_0_, aspnetprof0_.PropertyNames as Property3_168_0_, aspnetprof0_.PropertyValuesBinary as Property4_168_0_, aspnetprof0_.PropertyValuesString as Property5_168_0_ from eagle_prd.dbo.aspnet_Profile aspnetprof0_ where aspnetprof0_.UserId=?
Hibernate: select eagleuseri0_.UserId as UserId1_90_0_, eagleuseri0_.MobilePhone as MobilePh2_90_0_, eagleuseri0_.OfficePhone as OfficePh3_90_0_ from eagle_prd.dbo.EagleUserInfo eagleuseri0_ where eagleuseri0_.UserId=?
The hibernate Query.list() function fetches the complete object, including it's references as it creates a list that is detached from the hibernate scope.