on 10-11-2023 3:19 PM
Hi community,
we have a custom handler in CAP Java where we want to read a CDS entity with a property of type LargeBinary
This LargeBinary property is mapped in Java to type InputStream
When we use the method getContent to read the InputStream we are getting an exception and InputStream is null if the file is bigger than 1024 bytes.
We are getting this error message:
This only happens with HANA DB, with SQLITE it is working fine. If we check the content n SAP HANA Database Explorer the content is full available.
So what is the correct way to read a LargeBinaray (BLOB in HANA) with CAP JAVA?
Best regards and many thanks,
Chris
How do you execute the CqnSelect that returns you the book entity? You need to ensure that you retrieve the content InputStream within the active transaction. If there is no explicit transaction boundary opened around your code (e.g. in a background thread or custom RestController), you might need to open an explicit ChangeSetContext. This would look like this:
runtime.changeSetContext().run(changeSet -> {
Books book = service.run(Select.from(...)).single(Books.class);
InputStream content = book.getContent();
// make sure to consume the InputStream within the active transaction
// otherwise transaction is committed in HANA and connection returned to the pool
// which frees the resources not yet streamed
}
If you execute that code as part of an OData request coming from CAPs OData adapters the ChangeSetContext and transactional boundary should be there already by default.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
67 | |
8 | |
8 | |
6 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.