Oi
Estou usando o hibernate e todas as operações com hibernate esta disparando a seguinte excecao:
Exception in thread "main" org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
public static void main(String[] args) throws Exception {
DAOFactoryHibernate d = DAOFactoryHibernate.getInstance();
ModeloDAOHibernate dao = (ModeloDAOHibernate) d.makeModeloDAO();
Modelo modelo = (Modelo) dao.retrieve(3);
System.out.println(modelo.getNome());
}
e estou usando dao, seguese um pedaco da DAOFactoryHibernate:
public class DAOFactoryHibernate implements DAOFactory{
private SessionFactory sessionfactory;
private static DAOFactoryHibernate instance;
private DAOFactoryHibernate(){
try{
Configuration config = new Configuration();
Properties prop = new Properties(); prop.load(getClass().getResourceAsStream("map/config.properties"));
config.setProperties(prop);
config.configure(getClass().getResource("map/hibernate.cfg.xml"));
sessionfactory = config.buildSessionFactory();
}catch(Exception e){
e.printStackTrace();
}
}
public ModeloDAO makeModeloDAO(){
return new ModeloDAOHibernate(sessionfactory);
}
public static DAOFactoryHibernate getInstance(){
if(instance==null){
instance = new DAOFactoryHibernate();
}
return instance;
}
}
Att, Dirceu