When the user wants to create a lob-locator (mapped in the entity as a JDBC Blob/Clob/NClob), Hibernate provides a convenience for creating the lob-locator instance via the LobHelper obtained from the Session. LobHelper provides methods to create Blobs, Clobs and NClobs.
There are forms for each that accept an existing stream. Currently, how that gets handlesd and eventually passed to the database is inefficient. The problem is twofold.
First, we try to rely on the lob-locator creation of the JDBC driver if possible. THe problem there is that those methods do not accept and parameters. So you simply create an empty lob-locator which you then need to fill. And the only way to fill it given an InputStream is to copy that stream's content over. Which causes the stream data to be read into memory.
Second, we have a suboptimal implementation of copying streams from an in-memory lob-locator to the JDBC driver as a stream. Specifically, this is in cases where the LobHelper is not using the JDBC driver's lob creation methods, instead creating a "mock" lob.
|