休止状態使用している場合、私はSessionFactory
とSession
オブジェクトは、「してみてください-とリソース」、私は彼らのclose()
メソッドを呼び出すことは無視できないようにして働くことができるかどうかを確認したいと思います:`SessionFactory`と` Session`オブジェクトは "try-with-resource"で動作できません。
try (SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession()){
session.beginTransaction();
Customer customer = new Customer();
customer.setFirstName("James");
customer.setLastName("Bond");
customer.setSsn(999998);
customer.setAddressLine1("1111 S St");
customer.setCity("London");
customer.setState("LDN");
customer.setCountry("UK");
session.save(customer);
session.getTransaction().commit();
// session.close();
// sessionFactory.close();
} catch (Exception e) {
e.printStackTrace();
}
私はエラーを取得しますしかし:2つのクラスがAutoCloseable
インタフェースを実装していないので、
CustomerTest.java:12: error: incompatible types: try-with-resources not applicable to variable type
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
^
(SessionFactory cannot be converted to AutoCloseable)
CustomerTest.java:18: error: incompatible types: try-with-resources not applicable to variable type
Session session = sessionFactory.openSession()){
^
(Session cannot be converted to AutoCloseable)
2 errors
それは、SessionFactory
とSession
オブジェクトは、「してみてください-とリソース」で働くことができないことを意味するのでしょうか?
ありがとうございました。