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")
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.
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