dal link ho capito che bisogna tenere la sessione aperta anche in fase di view
...The second is to keep the session open until the view is done rendering (commonly referred to as 'Open Session In View')....
ora... come si fa a tenere una sessione aperta in visualizzazione?
vi posto il mio DAO
codice:
@SuppressWarnings("unchecked")
public List<Fattura> findLastFatturaByAziendaDataMyAzienda(final int idAzienda,
final int annoFattura, final int idMyAzienda) throws RuntimeException {
final String queryString =
"select f "
+ "from Fattura f "
+ "where f.azienda.id = :idAzienda "
+ "and year(f.data) = :annoFattura "
+ "and f.myAzienda.id = :idMyAzienda "
+ "and f.numero in (select max(f.numero) from Fattura f where f.azienda.id = :idAzienda and year(f.data) = :annoFattura and f.myAzienda.id = :idMyAzienda)";
return getJpaTemplate().executeFind(new JpaCallback() {
public Object doInJpa(EntityManager em) throws PersistenceException {
Query query = em.createQuery(queryString);
query.setParameter("idAzienda", idAzienda);
query.setParameter("annoFattura", annoFattura);
query.setParameter("idMyAzienda", idMyAzienda);
return query.getResultList();
}
});
}
per poi utilizzarlo attraverso
fattura.getAzienda().getZona().getZona_1();