{"id":7695,"date":"2012-09-21T21:27:24","date_gmt":"2012-09-21T15:57:24","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=7695"},"modified":"2022-01-13T16:46:44","modified_gmt":"2022-01-13T11:16:44","slug":"extract-correct-class-from-hibernate-object-wrapped-with-javassist","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/extract-correct-class-from-hibernate-object-wrapped-with-javassist\/","title":{"rendered":"Extract correct class from hibernate object wrapped with javassist"},"content":{"rendered":"<p>Hi,<\/p>\n<p>Some times when we access domain objects of collections in one to many or many to many\u00a0relationships,\u00a0we get Hibernate class wrapped with javassist, basically hibernate wraps all loaded objects with javassist\u00a0after loading(lazy loading case)\u00a0them .<\/p>\n<p>So if \u00a0we call \u00a0<code>class.name<\/code> on the members of collections in one to many or many to many relationships<span style=\"color: #000000\"> <\/span>we would get class names something like <code>com.test.classname_javassist_59<\/code>.<\/p>\n<p>So to solve this issue, hibernate provides a\u00a0<code><strong>HibernateProxyHelper<\/strong><\/code> class that has a static method to return the class without the wrapped javassist .<\/p>\n<pre><code>[java]HibernateProxyHelper.getClassWithoutInitializingProxy(object)[\/java]\r\n\r\n <\/code><\/pre>\n<p>This method returns the class \u00a0without the \u00a0javassist proxy of hibernate class. If the\u00a0<code>wrappedClassObject<\/code> is not proxied by javassist the original class will be returned. \ud83d\ude42<\/p>\n<p>Regards<br \/>\n$achin verma<br \/>\n<span style=\"color: #ff6600\">sachin.verma<\/span>@<span style=\"color: #0000ff\">intelligrape.com<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, Some times when we access domain objects of collections in one to many or many to many\u00a0relationships,\u00a0we get Hibernate class wrapped with javassist, basically hibernate wraps all loaded objects with javassist\u00a0after loading(lazy loading case)\u00a0them . So if \u00a0we call \u00a0class.name on the members of collections in one to many or many to many relationships [&hellip;]<\/p>\n","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":4},"categories":[7],"tags":[4840,265,420,990,989],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/7695"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=7695"}],"version-history":[{"count":1,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/7695\/revisions"}],"predecessor-version":[{"id":54654,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/7695\/revisions\/54654"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=7695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=7695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=7695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}