前提・実現したいこと
参考ソースはH2に接続していたので、postgresql用に変えたのですが接続できず、、
A5M2ソフトでpostgresqlに接続できたので、ソースの問題だと思っています。
エラーで検索しても解決できておらず。分かる方、教えて頂きたいです。
エラー
Exception in thread "main" org.seasar.doma.jdbc.JdbcException: [DOMA2056] トランザクション分離レベルの取得に失敗しました。原因は次のものです。org.postgresql.util.PSQLException: ResultSetは閉じられました。 at org.seasar.doma.jdbc.tx.LocalTransaction.beginInternal(LocalTransaction.java:211) at org.seasar.doma.jdbc.tx.LocalTransaction.begin(LocalTransaction.java:160) at Tester.main(Tester.java:12) Caused by: org.postgresql.util.PSQLException: ResultSetは閉じられました。 at org.postgresql.jdbc2.AbstractJdbc2ResultSet.checkClosed(AbstractJdbc2ResultSet.java:2662) at org.postgresql.jdbc2.AbstractJdbc2ResultSet.setFetchSize(AbstractJdbc2ResultSet.java:1779) at org.postgresql.jdbc4.Jdbc4Statement.createResultSet(Jdbc4Statement.java:37) at org.postgresql.jdbc2.AbstractJdbc2Statement$StatementResultHandler.handleResultRows(AbstractJdbc2Statement.java:209) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1771) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:510) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:372) at org.postgresql.jdbc2.AbstractJdbc2Connection.execSQLUpdate(AbstractJdbc2Connection.java:261) at org.postgresql.jdbc2.AbstractJdbc2Connection.getTransactionIsolation(AbstractJdbc2Connection.java:773) at org.seasar.doma.jdbc.tx.LocalTransactionalConnection.getTransactionIsolation(LocalTransactionalConnection.java:174) at org.seasar.doma.jdbc.tx.LocalTransaction.beginInternal(LocalTransaction.java:207) ... 2 more
Main.java
Tester.java
1import org.seasar.doma.jdbc.tx.LocalTransaction; 2 3import tutorial.AppConfig; 4import tutorial.dao.ServiceDao; 5import tutorial.dao.ServiceDaoImpl; 6import tutorial.entity.Service; 7 8public class Tester { 9 public static void main(String[] args) { 10 LocalTransaction tx = AppConfig.getLocalTransaction(); 11 try { 12 tx.begin(); 13 14 Service service = null; 15 16 ServiceDao serviceDao = new ServiceDaoImpl(); 17 service = serviceDao.selectName(); 18 19 tx.commit(); 20 } finally { 21 tx.rollback(); 22 } 23 } 24}
AppConfig.java
package tutorial; import javax.sql.DataSource; import org.seasar.doma.jdbc.DomaAbstractConfig; import org.seasar.doma.jdbc.SimpleDataSource; import org.seasar.doma.jdbc.dialect.Dialect; import org.seasar.doma.jdbc.dialect.PostgresDialect; import org.seasar.doma.jdbc.tx.KeepAliveLocalTransaction; import org.seasar.doma.jdbc.tx.LocalTransaction; import org.seasar.doma.jdbc.tx.LocalTransactionalDataSource; public class AppConfig extends DomaAbstractConfig { private static final DataSource originalDataSource = createDataSource(); private static final LocalTransactionalDataSource localTxDataSource = createLocalTxDataSource(); private static final Dialect dialect = new PostgresDialect(); @Override public DataSource getDataSource() { return localTxDataSource; } @Override public Dialect getDialect() { return dialect; } protected static DataSource createDataSource() { SimpleDataSource dataSource = new SimpleDataSource(); dataSource.setUrl("jdbc:postgresql://localhost:5432/データベース名"); dataSource.setUser("ユーザー"); dataSource.setPassword("パスワード"); return dataSource; } protected static LocalTransactionalDataSource createLocalTxDataSource() { return new LocalTransactionalDataSource(originalDataSource); } public static LocalTransaction getLocalTransaction() { return localTxDataSource.getLocalTransaction(defaultJdbcLogger); } public static KeepAliveLocalTransaction getKeepAliveLocalTransaction() { return localTxDataSource .getKeepAliveLocalTransaction(defaultJdbcLogger); } public static DataSource getOriginalDataSource() { return originalDataSource; } }