hibernate で遅延させるための dbadapter を作成しました。実際、私のクラスは次のようになります。
public class DBAdapter {
private static SessionFactory factory;
private static final ThreadLocal<Session> threadSession = new ThreadLocal();
public static Session OpenConnection() {
if (factory == null) {
factory = new Configuration().configure(
"com/et/hibernatexml/hibernate.cfg.xml")
.buildSessionFactory();
}
Session s = (Session) threadSession.get();
if (s == null)
{
s =factory.openSession();
threadSession.set(s);
}
return s;
}
public List selectQuery(String QueryString)
{ try
{
Session session=OpenConnection();
resultlist = query.list();
}
finally()
{
closeSession();
}
}
public static void closeSession()
{
Session session = (Session) threadSession.get();
threadSession.set(null);
if (session != null && session.isOpen()) {
session.flush();
session.close();
}
}
サーバーからデータを取得するために、私はこのようにします..
DBAdapter ob=new DBAdapter();
ob.setParameter("orgId", orgId);
List list=ob.selectQuery(queryvalue);
私の疑いは、このように扱うことによる問題です。特に、SessionFactory は静的変数なので??