Note that there are some explanatory texts on larger screens.

plurals
  1. POPrevent Dozer from triggering Hibernate lazy loading
    primarykey
    data
    text
    <p>I am using Spring transactions so the transaction is still active when POJO to DTO conversion occurs.</p> <p>I would like to prevent Dozer from triggering lazy loading, so that hidden sql queries never occur : all fetching has to be done explicitly via HQL (to get the best control on performances).</p> <ol> <li><p>Is it a good practice (I can't find it documented anywhere) ?</p></li> <li><p>How to do it safely ?</p></li> </ol> <p>I tried this before DTO conversion :</p> <pre><code>PlatformTransactionManager tm = (PlatformTransactionManager) SingletonFactoryProvider.getSingletonFactory().getSingleton("transactionManager"); tm.commit(tm.getTransaction(new DefaultTransactionDefinition())); </code></pre> <p>I don't know what happens to the transaction, but the Hibernate session doesn't get closed, and the lazy loading still occurs.</p> <p>I tried this :</p> <pre><code>SessionFactory sf = (SessionFactory) SingletonFactoryProvider.getSingletonFactory().getSingleton("sessionFactory"); sf.getCurrentSession().clear(); sf.getCurrentSession().close(); </code></pre> <p>And it prevents lazy loading, but is it a good practice to manipulate session directly in the application layer (which is called "facade" in my project) ? Which negative side effects should I fear ? (I've already seen that tests involving POJO -> DTO conversions could no more be launched through AbstractTransactionnalDatasource Spring test classes, because this classes try to trigger a rollback on a transaction which is no more linked to an active session).</p> <p>I've also tried to set propagation to NOT_SUPPORTED or REQUIRES_NEW, but it reuse the current Hibernate session, and doesn't prevent lazy loading.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload