If entity.getHistory() is null following code snippet:
(getEntityManager() returns spring injected EntityManager, database field history type is: text or varchar2(20
There's a simple fix: when you're building the query string, if a parameter is going to be null -- use "null" instead of "?".
As @araqnid says, Hibernate is incorrectly casting null values into type bytea because it doesn't know any better.