title: Hibernate @Lob on byte[] causes "Bad value for type long"
body: <p>I'm trying to lazily fetch single <code>byte[] content</code> java property using Hibernate under Spring Boot, accessing PostgreSQL database. So I pulled together testing app for testing different solutions. One of them required me to use <code>@Lob</code> annotation on said property, so I did. Now reading entity from the database leads to very curious error, precisely:</p>
  <p><code>Bad value for type long : \x454545454545445455</code></p>
  <p>The value <code>\x45...</code> is value of bytea column not the bigint one, why is it trying to force it into the long even though it's wrong column? Why annotation on one column somehow affects another one?
  As for fix, removing <code>@Lob</code> seems to work (at least in my stack) but the problem remains unexplained to me and I would like to know what is going rather than just blindly moving on. Is it bug or I am misunderstanding something completely?</p>
  <p>Entity:</p>
  <pre><code>@Entity
  @Table(name = &quot;blobentity&quot;)
  public class BlobEntity {
  
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
  
    @Lob //this annotation breaks code
    @Column(name = &quot;content&quot;)
    @Basic(fetch = FetchType.LAZY)
    private byte[] content;
  
    @Column(name = &quot;name&quot;)
    private String name;
    
    //getters/setters
  }
  </code></pre>
  <p>Repository:</p>
  <pre><code>@Repository
  public interface BlobRepo extends JpaRepository&lt;BlobEntity, Long&gt; {
  
  }
  </code></pre>
  <p>Calling code:</p>
  <pre><code>  @Autowired
    BlobRepo blobrepo;
  
    @GetMapping(&quot;lazyBlob&quot;)
    public String blob () {
  
      var t = blobrepo.findAll().get(0);
  
      var name = t.getName();
      var dataAccessedIfLazy = t.getContent();
  
      return t.getName();
    }
  </code></pre>
  <p>Postgres DDL:</p>
  <pre><code>CREATE TABLE test.blobentity (
      id bigserial NOT NULL DEFAULT nextval('test.blobentity_id_seq'::regclass),
      &quot;name&quot; varchar NULL,
      &quot;content&quot; bytea NULL,
      CONSTRAINT blobentity_pk PRIMARY KEY (id)
  );
  </code></pre>
  <p>Select result:</p>
  <p><a href="https://i.stack.imgur.com/Y6g9J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y6g9J.png" alt="select result" /></a></p>
  <p>Used version:</p>
  <p>PostgreSQL 10.4; springframework.boot 2.4.2; hibernate version that comes with this spring boot version</p>