we are using a collection level filtering to fetch only those collection of entities (CodeValues) whose particular property called 'cdfMeaning' matches a specidfied value, while fetching their parent CodeSet entity.
@Entity @Table(name = "CODE_SET") @FilterDef(name="filterCodeValue", parameters = @ParamDef(name = "cdfMeaning", type = "string")) public class CodeSet implements Serializable { private static final long serialVersionUID = -6782112102089236956L; private static final int CODE_SET_NAME = 256; @Id @Column(name = "CODE_SET", nullable = false, unique = true) private Long codeSet; @Column(name = "CODE_SET_NAME", nullable = false, length = CODE_SET_NAME, unique = true) private String name; @OneToMany (cascade={CascadeType.ALL}, mappedBy = "codeSet", fetch = FetchType.EAGER) @Filter(name="filterCodeValue", condition=":cdfMeaning = VALUE_CDF_MEANING") private List<CodeValue> codeValues = new ArrayList<CodeValue>();
the filter related annotation should make it clear. The problem we are facing is when trying to execute the below code for varies values of 'cdfMeaning ' ,
public CodeValue getUniqueCodeValue(String codeSetName, String cdfMeaning) { CodeValue codeValue = null; Session session = getSession(); session.enableFilter("filterCodeValue").setParameter("cdfMeaning", cdfMeaning); Criteria criteria = session.createCriteria(CodeSet.class); criteria.add(Restrictions.eq("name", codeSetName)); List<CodeSet> codeSets = criteria.list(); if (codeSets.isEmpty() || codeSets.get(0).getCodeValues().isEmpty()) return null; else { for (CodeSet codeSet: codeSets) { codeValue = codeSet.getCodeValues().get(0); } } return codeValue; }
first time it filters the data properly, but for subsequent filetring it returns what it returned for the first retrieval, for example if the value for cdfMeaning was 'REALTIME' the first time, it returns CodeSet entity which only contains CodeValues containing that passed in value, but second time when cdfMeaning = 'BATCH', it still returns the same result as before. We are not really sure what w eare missing here thats causing this problem, any help on this would be great.
regards Aravias
|