2

現在のアプリケーションでは、Hibernate + PostgreSQL を使用しています。特定のケースではCOPY、postgres で利用可能な機能を使用して、CSV ファイルからデータをロードする必要があります。COPYHibernateを使用する方法はありますか。

Postgres version : 9.4
Hibernate version : 5.0.6
4

1 に答える 1

4

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 );

これが読者に役立つことを願っています。

于 2016-01-29T06:55:47.107 に答える