Hi. I would like to hear someone else's toughts on something I noticed: suppose you have a Hibernate-managed POJO that has an interface like...
----------
public void setFlag(Integer flag);
public Integer getFlag();
public Boolean isFlag();
----------
The idea here is, for whatever reason, I choose to persist a field as an Integer, but sometimes it will be more convenient for me, in my application, to retrieve it as a Boolean (say if its stored value != 0). I expect Hibernate to use setFlag and getFlag for data persistency and retrieval, but isFlag is for my use alone; Hibernate does not and should not worry about it.
I tried to implement this behavior and had problems on Hibernate 3.1.3, because I could not tell it not to use isFlag to retrieve values instead of getFlag, as both are valid bean acessor method names.
This probably can be solved by a field accessor definition, or by implementing any accessor strategy that will deal with the ambiguity, but couldn't there be an automatic check of some sort to prevent the problem from ocurring in the first place? Hibernate knows from my .hbm file which type is the field, and given two methods could realize on its own which one suits it.
Thanks
|