現在のアプリケーションでは、Hibernate + PostgreSQL を使用しています。特定のケースではCOPY
、postgres で利用可能な機能を使用して、CSV ファイルからデータをロードする必要があります。COPY
Hibernateを使用する方法はありますか。
Postgres version : 9.4
Hibernate version : 5.0.6
現在のアプリケーションでは、Hibernate + PostgreSQL を使用しています。特定のケースではCOPY
、postgres で利用可能な機能を使用して、CSV ファイルからデータをロードする必要があります。COPY
Hibernateを使用する方法はありますか。
Postgres version : 9.4
Hibernate version : 5.0.6
session.doWork
@a-horse-with-no-name コメントに基づいて、廃止された次のコードをまとめました。
SessionFactory factory = HibernateUtil.getSessionFactory();
Session session = factory.openSession();
SessionImplementor sessImpl = (SessionImplementor) session;
Connection conn = null;
conn = sessImpl.getJdbcConnectionAccess().obtainConnection();
CopyManager copyManager = new CopyManager((BaseConnection) conn);
File tf =File.createTempFile("temp-file", "tmp");
String tempPath =tf.getParent();
File tempFile = new File(tempPath + File.separator + filename);
FileReader fileReader = new FileReader(tempFile);
copyManager.copyIn("copy testdata (col1, col2, col3) from STDIN with csv", fileReader );
これが読者に役立つことを願っています。