How to stream data to database BLOB using Hibernate (no in-memory storing in byte[])

前端 未结 3 491
死守一世寂寞
死守一世寂寞 2020-12-14 12:51

I\'m looking for a way to stream binary data to/from database. If possible, i\'d like it to be done with Hibernate (in database agnostic way). All solutions I\'ve found invo

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-14 13:25

    Your solution using Hibernate's lobHelper should work, but you may need to make sure that the use of streams is enforced. Set property hibernate.jdbc.use_streams_for_binary = true This is a system-level property, so it has to be set at startup (I defined it on the command line during testing:

    java -Dhibernate.jdbc.use_streams_for_binary=true blobTest
    

    You can prove it's changed in your code:

    Object prop = props.get("hibernate.jdbc.use_streams_for_binary");
    System.out.println("hibernate.jdbc.use_streams_for_binary" + "/" + prop);
    

提交回复
热议问题