java - JPA/Hibernate instance of not working -


imagine situation:

@javax.persistence.inheritance(strategy=javax.persistence.inheritancetype.joined) @javax.persistence.discriminatorcolumn @javax.persistence.entity @javax.persistence.table(name="parent") public abstract class parent{ ... }  @javax.persistence.entity @javax.persistence.table(name="a") public class extends parent{ ... }  @javax.persistence.entity @javax.persistence.table(name="b") public class b extends parent{ ... }   parent p = new a(); 

now call this:

p instance of 

always returns false!!

works ok on openjpa!

should file bug? hibernate 4.3.10

this because hibernate returning proxy.

why this? implement lazy loading framework needs intercept method calls return lazy loaded object or list of objects. can first load object db , allow method run. hibernate creating proxy class. if check type in debug should able see actual type generated class not extend base class.

how around it? had problem once , used visitor pattern instead of using instanceof. add complication it's not everyone's favorite pattern imho cleaner approach using instanceof.

if use instanceof typically end if...else blocks checking different types. add more types have re-visit each of these blocks. advantage of visitor pattern conditional logic built class hierarchy if add more types makes less need change everywhere uses these classes.

i found article useful when implementing visitor pattern.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -