I don’t know if I can do this. I have an attribute where I store with hibernate an String: String tags this property could value for example: tags="car,airplane,bycicle"
Now I would like get the instances which its tags value contain the substring “car”:
Object A --> tags="car,airplane"
Object B --> tags="bycicle"
Object C --> tags="bycicle,car"
Return A and C
There is any way to do this?
I try to classify the object by tags and then restore objects which contains one or more specific tags.
The idea is to do same that Stackoverflow does with tags field when you go to ask a question.
This is exactly why database normalization is important. Multiple values should never be stored in a single column. You should have a Tag entity, and have a ManyToMany association between your entity and the Tag entity. If you had that, you could simply do
With your current design, your best bet is to do
but this will be much slower, and will return posts having the tags careful or vacarm.