gpc / taggable

Taggable Grails Plugin
http://grails.org/plugin/taggable
Other
12 stars 23 forks source link

Invalid tag_link types in case of 'lazy' hibernate proxies #3

Closed trybuy closed 2 years ago

trybuy commented 10 years ago

Hi there, In cases when Hibernate uses 'lazy' loading of domain object it doesn't actually create a full object of the specific type but only a proxy which has different type name than original one. This results in wrong behaviour of taggable. For example: Lets say there is an domain object: class Book { Author author }

def book = Book.get(3453) book.author.addTag("test")

will end up as database call similar to this:

insert into tag_links (actor_id, date_created, tag_id, tagref, type) values (null, '2014-05-21 13:27:03', 14, 90, 'author$$_javassist_190')

book.author is in fact javassist hibernate proxy not a real Author object. So if there is a subsequent call:

def author = Author.get(567567) author.getTagLinks()

it will do: select ... taglinks this inner join tags tag2 on this.tagid=tag2.id where this_.tagid=14 and this.tagref=90 and this.type='autor' limit 1

and fail to find the tag because the type is obviously different.

One way to fix it - is to change: GrailsNameUtils.getPropertyName(instance.class) calls in TaggableGrailsPlugin.groovy onto: GrailsNameUtils.getPropertyName(Hibernate.getClass(instance)) - Hibernate.getClass() properly resolves class of the object event if it's a proxy.

BR

github-actions[bot] commented 2 years ago

This issue looks like it is stale and therefor it is in risk of being closed with no further action.