Question

A pojo for hibernate, which has a Lob field, and it's type is byte[]:

import javax.persistence.*;
import java.io.Serializable;
import static javax.persistence.AccessType.FIELD;

@Entity
@Access(FIELD)
@Table(name = "MYFILE")
public class MyFile implements Serializable {

    @Id
    @SequenceGenerator(name = "MYSEQ", sequenceName = "MYSEQ", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MYSEQ")
    @Column(name = "ID")
    private Long id;


    @Column(name = "FILE_CONTENT")
    @Lob
    private byte[] fileContent;

    // getters and setters

}

Then I read an empty file and save it to database:

MyFile file = new MyFile();
file.setFileContent(new byte[0]);

sessionFactory.getCurrentSession().save(file);

I want to load it in another transaction:

MyFile myFile = sessionFactory.getCurrentSession().query("...").uniqueResult();
System.out.println(myFile.fileContent);

It prints:

null

I don't understand why the field fileContent is null, should not it be new byte[0]?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top