0

I would like to create criteria or add restriction to my existing criteria (i think it has to be criteria) that will ignore "-" when searching for data's.

E.g I'm searching for number "888" and I would like to get "8-8-8" too.

I have bean that contains my number field

A.java

@Data
public class A {
    [...]
    @Length(max = 16)
    @Column(length = 16)
    private String number; 
}

And here's my criteria

    public Pair<Long, List<A>> filter(CompoundFilter filter, CompoundSort sort, int start, int count) {
        Criteria criteria = getSession().createCriteria(A.class, "a_alias");
...
}

What should I add to criteria to achieve my goal?

My other idea is to create some hidden field (by hidden i mean the one that i wont use on UI, only fill with datas) that will hold "transformed" values and when filtering number i will filter on this field

lukaszrys
  • 1,656
  • 4
  • 19
  • 33

1 Answers1

0

try using regex ,the pattern would look like "[0-9]-[0-9]- ... [0-9]" , here instead of 0-9 build the pattern with your desired number. If i understood your question correctly then this could be an answer.

GIRISH RAMNANI
  • 614
  • 6
  • 18