hazelcast不等于谓词搜索集合属性

时间:2017-02-14 21:32:59

标签: hazelcast

我使用hazelcast地图来存储与以下内容非常类似的对象:

@Entity
@Table(name = "organization")
public class Organization
{
    public static final String MAP_NAME = "organizations";

    @Id
    @Column(name = "organizationId", unique = true, nullable = false, columnDefinition = "VARCHAR(36)")
    protected String organizationId = UUID.randomUUID().toString();

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "organizationId")
    private Set<RecordKeeperConfig> recordKeeperConfigs;
}

RecordKeeperConfig的定义如下:

@Entity
@Table(name = "recordKeeperConfig")
public class RecordKeeperConfig
{
    public static final String MAP_NAME = "recordKeeperConfig";

    @Id
    @Column(name = "recordKeeperConfigId", unique = true, nullable = false, columnDefinition = "VARCHAR(36)")
    protected String recordKeeperConfigId = UUID.randomUUID().toString();

    @Column(name = "organizationId", columnDefinition = "VARCHAR(36)")
    protected String organizationId;

    @Enumerated(EnumType.STRING)
    @Column(name = "type", length = 8)
    protected RecordKeeperType type;
}

最终我想要回到一个至少有一个RecordKeeperConfig的所有组织对象的集合。我尝试使用Predicate.notEqual(“recordKeeperConfigs”,null),但它产生以下异常:

java.lang.IllegalArgumentException: Cannot use NotEqualPredicate predicate with an array or a collection attribute

1 个答案:

答案 0 :(得分:0)

尝试将逻辑操作实现为实体类中的瞬态方法。然后代替集合,构建Hazelcast谓词:

方法:

EntryObject e = new PredicateBuilder().getEntryObject();
PredicateBuilder predicate = e.is("recordKeeperConfigsNotEmpty");
Collection<Organization> filteredOrganizations = organizationMap.values(predicate);

谓词:

public static FileContentResult ExportChildernsToExcel(string districtID, string districtName)
{
    string filePath = HttpContext.Current.Server.MapPath("~/ExcelBackup/FileToDownload/DistrictwiseChildrens.xlsx").ToString();

    return File(filePath, "application/vnd.ms-excel", districtName + "_Childrens.xlsx");
}