Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EclipseLink - Invalid query key [latestVersionFlag] in expression

I just upgraded from Toplink to EclipseLink and am running in to this error

Exception [EclipseLink-6015] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.QueryException Exception Description: Invalid query key [latestVersionFlag] in expression. Query: ReadAllQuery(name="bookingVersionCollection" referenceClass=BookingVersion )

My descriptor looks like this

OneToManyMapping bookingVersionCollectionMapping = new OneToManyMapping();
bookingVersionCollectionMapping.setAttributeName("bookingVersionCollection");
bookingVersionCollectionMapping.setReferenceClass(BookingVersion.class);
bookingVersionCollectionMapping.useTransparentCollection();
bookingVersionCollectionMapping.useCollectionClass(IndirectList.class);
bookingVersionCollectionMapping.addAscendingOrdering("bookingVersionID");
bookingVersionCollectionMapping.addTargetForeignKeyFieldName("RS_BOOKINGVERSION.RS_BKG_ID", "RS_BOOKING.RS_BKG_ID");
bookingVersionCollectionMapping.setSelectionCriteria(bookingVersionCollectionMapping.buildSelectionCriteria()
    .and(expBuilder.get("latestVersionFlag").equal(ResConstants.FLAG_YES)));
descriptor.addMapping(bookingVersionCollectionMapping);

I also have a mapping for BookingVersion class that has the mapping for that field

DirectToFieldMapping latestVersionFlagMapping = new DirectToFieldMapping();
latestVersionFlagMapping.setAttributeName("latestVersionFlag");
latestVersionFlagMapping.setFieldName("RS_BOOKINGVERSION.LATESTVERSIONFLAG");
descriptor.addMapping(latestVersionFlagMapping);

And inside the Java poco object of BookingVersion.java that field looks like this..

private char latestVersionFlag = ResConstants.FLAG_YES;

Any ideas? This code worked in Toplink, so not sure what's going on.

like image 614
Nicholas Mayne Avatar asked Nov 09 '22 01:11

Nicholas Mayne


1 Answers

Well, by changing

bookingVersionCollectionMapping.setSelectionCriteria(bookingVersionCollectionMapping.buildSelectionCriteria()
    .and(expBuilder.get("latestVersionFlag").equal(ResConstants.FLAG_YES)));

to

bookingVersionCollectionMapping.setSelectionCriteria(bookingVersionCollectionMapping.buildSelectionCriteria()
      .and(expBuilder.getField("RS_BOOKINGVERSION.LATESTVERSIONFLAG").equal(ResConstants.FLAG_YES)));

seems to work..... still not sure why, but thought I would post for anyone else!

like image 73
Nicholas Mayne Avatar answered Nov 15 '22 05:11

Nicholas Mayne