JPQL Querying Bit Flags - jpql

I Have in my msql table column of type Long, this column represent bit falgs.
I need to select objects for which all of several flags are set :
columnValue & flags = columnValue
I try :
javax.persistence.Query q = getEntityManager().createQuery("SELECT u FROM Userattributes u WHERE u.myValueFlags & mask := mask");
q.setParameter("mask", mask);
But i have a syntax error :
Caused by: java.lang.IllegalArgumentException: An exception occurred
while creating a query in EntityManager: Exception Description:
Syntax error parsing the query [SELECT u FROM Userattributes u WHERE
u.userattributesPK.attributeID =:attributeId and u.myValueFlags & mask
:= mask], line 1, column 103: unexpected token [mask]. Internal
Exception: NoViableAltException(78!=[652:1:
simpleConditionalExpressionRemainder[Object left] returns [Object
node] : (n= comparisonExpression[left] | (n1= NOT )? n=
conditionWithNotExpression[(n1!=null), left] | IS (n2= NOT )? n=
isExpression[(n2!=null), left] );])
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1328)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createQuery(EntityManagerWrapper.java:425)

That cannot be done because JPQL does not have support for bitwise operations.

Related

Attempting to join: error "Conversion failed when converting from a character string to uniqueidentifier."

I am getting the following error when attempting to join on two ID fields:
select top 10 *
from SOURCECODE as s
inner join APPEAL as a on s.APPEALID = a.APPEALID;
error: Conversion failed when converting from a character string to uniqueidentifier.
Any ideas on how to fix?
Do I need to convert the fields?
The s.appealid is nvarchar 36
The a.appealid is uniqueidentifier
SELECT TOP 10 *
FROM SOURCECODE AS s
INNER JOIN APPEAL AS a ON CONVERT(uniqueidentifier, s.APPEALID) = a.APPEALID;

Databricks SQL, error when running update with join

I am trying to run an update on a Delta table and I am getting the following error.
Error in SQL statement: ParseException:
mismatched input 'from' expecting <EOF>(line 3, pos 0)
I really can't figure out why I get this error. Can anyone help me?
update eff
set eff.ACP = ia.COSTVALUE
from views.test_acp_effect eff
left join source_tables_db.ia_master_items ia
on eff.CODE = ia.IMM_CODE
where eff.DXN_Period = (
select td.MY_FISCAL_PERIOD_ABBR
from timedelta td
where current_date() between td.MIN_P_DATE
and td.MAX_P_DATE
)
and eff.CODE = source_tables_db.ia_master_items.IMM_CODE

jpql query with date literal causes IllegalArgumentException

I am trying to write query with date literal:
SELECT r
FROM Restaurant r
LEFT JOIN r.dishes dh ON dh.date = {d '2019-12-31'}
GROUP BY r
But when running I get an error
java.lang.IllegalArgumentException: org.hibernate.QueryException: unexpected char: '{'
What's wrong?
Try use only date in ISO format
SELECT r
FROM Restaurant r
LEFT JOIN r.dishes dh ON dh.date = '2019-12-31'
GROUP BY r

linq to entities: compare string variable with NVarchar field

This code results in timeout exception
String City_Code = null;
var result = (from r in myContext.TableA
where ( City_Code == r.City_Code )
select r ).ToList();
while this code will return quickly
String City_Code = null;
var result = (from r in myContext.TableA
where ( r.City_Code == City_Code )
select r ).ToList();
The difference is in the order of operands of the equality. The field City_Code of table TableA is of type nvarchar(20).
What is a possible reason for that???
update: The generated tsql for the 2 queries are identical except for that part: the first one has the condition " #p__linq__2 = [Extent1].[City_Code])" while the second has " [Extent1].[City_Code] = #p__linq__2)"
The value of #p_linq_2 when I notice the time difference is NULL. If I run the queries in ssms with NULL in place of #p_linq_2 they respond both very quickly

Orchard SpecFlow test does not run Migrations of a module correctly

How can i correct the following error? Can't run SpecFlow test as there is the error.
NHibernate.AdoNet.AbstractBatcher Error: 0 : Could not execute command: INSERT INTO ..._TaxonomyCatalogPartRecord (General, Reproduction, Identification, Culture, Evolution, Morphology, Id) VALUES (#p0, #p1, #p2, #p3, #p4, #p5, #p6)
NHibernate.Util.ADOExceptionReporter Error: 0 : The column name is not valid. [ Node name (if any) = ,Column name = Evolution ]
Orchard.ContentManagement.DefaultContentManager Error: 0 : GenericADOException thrown from IContentHandler by Orchard.Autoroute.Handlers.AutoroutePartHandler
NHibernate.AssertionFailure Error: 0 : An AssertionFailure occurred - this may indicate a bug in NHibernate or in your custom types.
NHibernate.Impl.AbstractSessionImpl Error: 0 : DTC transaction prepre phase failed
The two columns weren't created for a TaxonomyCatalogPartRecord of my module. It seems that the Migrations of my module wasn't run correctly.
The Migrations have the following methods:
"Create()" returns 5
"UpdateFrom5()" returns 8
"UpdateFrom8()" returns 9
"UpdateFrom9()" returns 10
The table is created in Create():
SchemaBuilder.CreateTable(
"TaxonomyCatalogPartRecord",
table =>
table
.ContentPartRecord()
.Column<string>("General", c => c.Unlimited())
.Column<string>("Reproduction", c => c.Unlimited())
.Column<string>("Identification", c => c.Unlimited())
.Column<string>("Culture", c => c.Unlimited())
);
The two columns are added in UpdateFrom9() with the following code:
SchemaBuilder.AlterTable("TaxonomyCatalogPartRecord", t => {
t.AddColumn<string>("Evolution");
t.AddColumn<string>("Morphology");
});
Also there were the following errors during SpecFlow run:
NHibernate.AdoNet.AbstractBatcher Error: 0 : Could not execute query: SELECT this_.Id as Id11_0_, this_.SerialNumber as SerialNu2_11_0_ FROM Settings_ShellDescriptorRecord this_ WHERE 1=1
NHibernate.Util.ADOExceptionReporter Error: 0 : The specified table does not exist. [ Settings_ShellDescriptorRecord ]
NHibernate.Util.ADOExceptionReporter Error: 0 : The specified table does not exist. [ Settings_ShellDescriptorRecord ]
And the following:
NHibernate.AdoNet.AbstractBatcher Error: 0 : Could not execute query:
SELECT this_.Id as Id338_6_, this_.Number as Number338_6_, this_.Published as Published338_6_, this_.Latest as Latest338_6_, this_.Data as Data338_6_, this_.ContentItemRecord_id as ContentI6_338_6_, autoroutep4_.Id as Id269_0_, autoroutep4_.UseCustomPattern as UseCusto2_269_0_, autoroutep4_.CustomPattern as CustomPa3_269_0_, autoroutep4_.DisplayAlias as DisplayA4_269_0_, autoroutep4_.ContentItemRecord_id as ContentI5_269_0_, titlepartr5_.Id as Id270_1_, titlepartr5_.Title as Title270_1_, titlepartr5_.ContentItemRecord_id as ContentI3_270_1_, contentite1_.Id as Id337_2_, contentite1_.Data as Data337_2_, contentite1_.ContentType_id as ContentT3_337_2_, termpartre2_.Id as Id273_3_, termpartre2_.TaxonomyId as TaxonomyId273_3_, termpartre2_.Path as Path273_3_, termpartre2_.Count as Count273_3_, termpartre2_.Selectable as Selectable273_3_, termpartre2_.Weight as Weight273_3_, commonpart8_.Id as Id294_4_, commonpart8_.OwnerId as OwnerId294_4_, commonpart8_.CreatedUtc as CreatedUtc294_4_, commonpart8_.PublishedUtc as Publishe4_294_4_, commonpart8_.ModifiedUtc as Modified5_294_4_, commonpart8_.Container_id as Container6_294_4_, contenttyp9_.Id as Id339_5_, contenttyp9_.Name as Name339_5_
FROM Orchard_Framework_ContentItemVersionRecord this_ left outer join Orchard_Autoroute_AutoroutePartRecord autoroutep4_ on this_.Id=autoroutep4_.Id left outer join Title_TitlePartRecord titlepartr5_ on this_.Id=titlepartr5_.Id inner join Orchard_Framework_ContentItemRecord contentite1_ on this_.ContentItemRecord_id=contentite1_.Id inner join Contrib_Taxonomies_TermPartRecord termpartre2_ on contentite1_.Id=termpartre2_.Id left outer join Common_CommonPartRecord commonpart8_ on contentite1_.Id=commonpart8_.Id left outer join Orchard_Framework_ContentTypeRecord contenttyp9_ on contentite1_.ContentType_id=contenttyp9_.Id WHERE this_.Published = #p0
NHibernate.Util.ADOExceptionReporter Error: 0 : The specified table does not exist. [ Contrib_Taxonomies_TermPartRecord ]
NHibernate.Util.ADOExceptionReporter Error: 0 : The specified table does not exist. [ Contrib_Taxonomies_TermPartRecord ]
Orchard.Exceptions.DefaultExceptionPolicy Error: 0 : An unexpected exception was caught
NHibernate.AdoNet.AbstractBatcher Error: 0 : Could not execute query: SELECT this_.Id as Id338_6_, this_.Number as Number338_6_, this_.Published as Published338_6_, this_.Latest as Latest338_6_, this_.Data as Data338_6_, this_.ContentItemRecord_id as ContentI6_338_6_, autoroutep4_.Id as Id269_0_, autoroutep4_.UseCustomPattern as UseCusto2_269_0_, autoroutep4_.CustomPattern as CustomPa3_269_0_, autoroutep4_.DisplayAlias as DisplayA4_269_0_, autoroutep4_.ContentItemRecord_id as ContentI5_269_0_, titlepartr5_.Id as Id270_1_, titlepartr5_.Title as Title270_1_, titlepartr5_.ContentItemRecord_id as ContentI3_270_1_, contentite1_.Id as Id337_2_, contentite1_.Data as Data337_2_, contentite1_.ContentType_id as ContentT3_337_2_, taxonomypa2_.Id as Id272_3_, taxonomypa2_.TermTypeName as TermType2_272_3_, commonpart8_.Id as Id294_4_, commonpart8_.OwnerId as OwnerId294_4_, commonpart8_.CreatedUtc as CreatedUtc294_4_, commonpart8_.PublishedUtc as Publishe4_294_4_, commonpart8_.ModifiedUtc as Modified5_294_4_, commonpart8_.Container_id as Container6_294_4_, contenttyp9_.Id as Id339_5_, contenttyp9_.Name as Name339_5_ FROM Orchard_Framework_ContentItemVersionRecord this_ left outer join Orchard_Autoroute_AutoroutePartRecord autoroutep4_ on this_.Id=autoroutep4_.Id left outer join Title_TitlePartRecord titlepartr5_ on this_.Id=titlepartr5_.Id inner join Orchard_Framework_ContentItemRecord contentite1_ on this_.ContentItemRecord_id=contentite1_.Id inner join Contrib_Taxonomies_TaxonomyPartRecord taxonomypa2_ on contentite1_.Id=taxonomypa2_.Id left outer join Common_CommonPartRecord commonpart8_ on contentite1_.Id=commonpart8_.Id left outer join Orchard_Framework_ContentTypeRecord contenttyp9_ on contentite1_.ContentType_id=contenttyp9_.Id WHERE this_.Published = #p0
NHibernate.Util.ADOExceptionReporter Error: 0 : The specified table does not exist. [ Contrib_Taxonomies_TaxonomyPartRecord ]
NHibernate.Util.ADOExceptionReporter Error: 0 : The specified table does not exist. [ Contrib_Taxonomies_TaxonomyPartRecord ]
Orchard.Exceptions.DefaultExceptionPolicy Error: 0 : An unexpected exception was caught
Change your AlterTable method to two separate calls of the AlterTable method, like so:
SchemaBuilder.AlterTable("TaxonomyCatalogPartRecord", t => t.AddColumn<string>("Evolution"));
SchemaBuilder.AlterTable("TaxonomyCatalogPartRecord", t => t.AddColumn<string>("Morphology"));
Or possibly your syntax is wrong and it should be
SchemaBuilder.AlterTable("TaxonomyCatalogPartRecord", t => {
t.AddColumn<string>("Evolution"),
t.AddColumn<string>("Morphology")
});
But I'm not sure about that one. Good luck

Resources