我刚刚从Toplink升级到EclipseLink,并遇到此错误
异常[EclipseLink-6015](Eclipse Persistence Services-2.6.1.v20150916-55dc7c3):org.eclipse.persistence.exceptions.QueryException异常描述:表达式中无效的查询键[latestVersionFlag]。查询:ReadAllQuery(name =“bookingVersionCollection” referenceClass = BookingVersion)
我的描述符看起来像这样
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);
我也有一个BookingVersion类的映射,该映射具有该字段的映射
DirectToFieldMapping latestVersionFlagMapping = new DirectToFieldMapping();
latestVersionFlagMapping.setAttributeName("latestVersionFlag");
latestVersionFlagMapping.setFieldName("RS_BOOKINGVERSION.LATESTVERSIONFLAG");
descriptor.addMapping(latestVersionFlagMapping);
在BookingVersion.java的Java poco对象中,该字段看起来像这样。
private char latestVersionFlag = ResConstants.FLAG_YES;
有任何想法吗?该代码在Toplink中有效,因此不确定发生了什么。
最佳答案
好吧,通过改变
bookingVersionCollectionMapping.setSelectionCriteria(bookingVersionCollectionMapping.buildSelectionCriteria()
.and(expBuilder.get("latestVersionFlag").equal(ResConstants.FLAG_YES)));
至
bookingVersionCollectionMapping.setSelectionCriteria(bookingVersionCollectionMapping.buildSelectionCriteria()
.and(expBuilder.getField("RS_BOOKINGVERSION.LATESTVERSIONFLAG").equal(ResConstants.FLAG_YES)));
似乎有效.....仍然不确定为什么,但以为我会为其他人发帖!