Hi everyone,
my problem is about a "collection-of-value" in an onPostUpdate Eventlistener:
onPostUpdate in the PostUpdateEvent I check getOldState against getState and all properties differ correctly except the set of strings.
It's the same Set in oldState and in state (always the new set):
The Object has a set of strings like this:
set<String> tags;
It's mapped like this:
<set name="tags" table="search_demo_person_tags" lazy="true">
<key column="object_id"/>
<element column="tag" type="string"/>
</set>
The object is saved by:
session.merge(object);
I load the object, set a new set of strings and i call merge.
In the postUpdateEvent in both oldState and state the same (the new) set of strings is presented.
I tried setting lazy="false" but that doesn't change anything (why would it).
Is there a way to fix this?
Why do I want/need this?
My plan is to keep track of how many objects have a given string in their set. - If the oldState and State would differ correctly i could decrease/increase the count for the missing/added string.
The set of strings represents a set of tags given to a business object by the users.
I can't use a set of Tags (and implement a Tag class) because that would mean all Tags end up in the same db-table and the businessobjects only have a table with foreign keys to that global tag table.
(With the strings each businessobject type has its own table, that's required.)
The only half solution i found on my own is to use an array of strings. (there the difference is correct between oldState and state) - But it has a very very big downside - it can't be loaded lazy... so every business-object needs two selects to be loaded even if the tags are unimportant for the performed operation, that is not really acceptable.
Well thanks for reading, and i hope somebody will be able to provide a tip.
ps: just noticed that this is maybe more of a hibernate than a hibernate-search problem.. i don't want to double post, so if somebody could move this, that would be great.
|