Java/Hibernate: How to detect, if field is lazy-loaded proxy and not actual data? -
i'm converting entity dto , want set null dto value fields, lazy-loaded , not initialized (because not want transfer data time).
i've tried:
if (!(entity.getnationality() instanceof hibernateproxy)) this.setnationalityfromentity(entity.getnationality());
but did not seemed help. suggestions welcome!
thank you!
they way in our entities have boolean methods check in way not trigger lazy loading. example, if our entity had associated entity called 'associatedsomething', method check if associated entity has been lazy loaded be:
public boolean isassociatedsomethingloaded() { if (associatedsomething instanceof hibernateproxy) { if (((hibernateproxy)associatedsomething).gethibernatelazyinitializer().isuninitialized()) { return false; } } return (getassociatedsomething() != null); }
note: it's important not use getassociatedsomething()
in check, makes sure associated entity not lazy-loaded during check.
Comments
Post a Comment