최대 절전 모드와 개찰구를 배우려고하는 임. 실제로 절전 세션을 열고 닫을 때 확실하지 않습니다. 저는 세션 팩토리에 대해 많은 것을 검색하고 많은 것을 읽었습니다. 그러나 저는 여전히 그것을 얻지 못합니다.최대 절전 모드 세션 처리
데이터베이스의 일부 데이터를 가져 와서 브라우저의 테이블에 표시하고 싶습니다. 해당 사이트에 처음으로 메신저 경우 즉 실제로 작동하지만, 내가 다시 그 사이트에 뒤로 버튼을 사용하여 가면 그것은 나에게이 오류 보여줍니다 : 나는 조기 또는 뭔가 내 SessionFactory를 닫습니다 때문에
가Last cause: Unknown service requested [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]
내가 그 생각을 그런 식으로. 하지만 문제를 해결하는 방법을 모른다.
내 자바 클래스 :
public class CategoryPanel extends Panel {
private WebMarkupContainer categoryContainer;
public CategoryPanel(String id) {
super(id);
SessionFactory sessionFactory = DbFactory.getSessionFactory(); // creating the Session Factory
StandardDao<Category> categoryDao = StandardDao.getInstance(sessionFactory); // creating dao to access data
List<Category> categoryList = categoryDao.getAll(Category.class); // get data of the db
CategoryDataProvider dataProvider = new CategoryDataProvider(categoryList);
categoryContainer = new WebMarkupContainer("categoryTable");
final DataView dv = new DataView("categoryList", dataProvider) {
@Override
protected void populateItem(Item item) {
final Category category = (Category) item.getModelObject();
final CompoundPropertyModel<Category> categoryModel = new CompoundPropertyModel<Category>(category);
item.add(new Label("catTitle", categoryModel.bind("title")));
}
};
categoryContainer.add(new Label("categoryTitle", Model.of("Titel")));
add(categoryContainer);
sessionFactory.close(); // here I close the factory, this seems to be wrong. I dont know if i close it anyway..
}
}
내 다오 :
public class StandardDao<T> {
private static StandardDao instance = null;
private static final Object syncObject = new Object();
private SessionFactory sessionFactory;
private StandardDao(SessionFactory session){
this.sessionFactory = session;
}
public static StandardDao getInstance(SessionFactory session) {
if (instance == null) {
synchronized (syncObject) {
if (instance == null) {
instance = new StandardDao(session);
}
}
}
return instance;
}
public List<T> getAll(Class theClass) {
List<T> entity = null;
Session session = sessionFactory.openSession();
try {
entity = session.createCriteria(theClass).list();
} catch (RuntimeException e) {
e.printStackTrace();
}finally {
session.flush();
// if I close the session here, I cant load lazy
}
return entity;
}
}