javastringcase-sensitivecase-insensitivegigaspaces

How to create case-insensitive field on Java POJO. Looking for a good design.


So I'm using GigaSpaces XAP with Hibernate plugin to load my DB table into the their grid cache, unfortunately for querying the grid they do not support directly case insensitive searches.

They offered 2 solutions:
1- Use LIKE query (same as SQL) which is slow (Wont even bother with this)
2- Create a separate property of the fields I want to have case insensitive.

So now my choices are:
1- Create an extra column in DB to have case-insensitive field (Not in this life time)
2- Create a custom data loader plugin for XAP such that the moment the data is loaded the field is stored in a "ToLower" properperty. (Supported but will leave as last resort)

I'm definitely not going with #1 and I will leave the custom data loader as a last result. So my idea is to...

class Person {
    String firstName
    String firstNameLower

    public void setFirstName(String firstName) {
        this.firstName = firstName

        this.firstNameLower = firstName.toLowerCase(...);
    }
}

Will this work with Hibernate? As the GigaSpace dataloader uses Hibernate and my pojo is pretty much an Entity class. I'm using Hibernate XML mapping not annotations. The "ToLower" fields will not be mapped. Does Hibernate call setXXX() on all fields that are mapped or does it do some fancy code replacement under the hood and doesn't call the setXXX() methods.

I'm also thinking an annotation would be good use here but not sure how to implement them or even if it's possible for this case.


Solution

  • For anyone interested.

    Simply create a "tolower()" method of the field and add the index annotation on that and you can map your pojo to hibernate the usual way.