Does anyone know how to go about designing tag system similar to the one used here, at stackoverflow?
Any links that would explain on how to go about implementing this system with hibernate/spring would be awesome.
I’m just looking for some starting point.
I would suggest starting with three
Entities, one for the object that is being tagged (is in the case of the SO example, this would be aPost), one for holding your tag definitions (you can just call thisTag), and one for mapping between the two (call this oneTaggedPost).Then the basic process of assigning a
Tagto aPostgoes something like:Tagwith the given name already exists, if yes, use the existing one, otherwise insert a new one.TaggedPostinstance that links thePostwith theTagfrom step 1.To remove a
Tagfrom aPostyou just delete the correspondingTaggedPostentity.You can use Hibernate annotations to expose the set of tags that are applied to a given
Postas a Java Collection so that you can just saygetTags()to get all the tags. And you can do the same thing onTagso that you can saygetPosts()to get all the posts that have a givenTag.