nobody
nobody

Reputation: 1949

How to Insert Clob using JPA

We have a problem where we need to keep the copy of an input file in DB(regulatory purposes). The file can be of size upto 1GB. Is there any way (using streaming and incremental updates) to insert the entire file into DB using JPA ?

Upvotes: 2

Views: 5692

Answers (2)

James
James

Reputation: 18379

If the file can really be 1g and you don't have > 1g of RAM, then your best bet is probably raw JDBC using streams on the file and the JDBC Blob.

Upvotes: -1

logan
logan

Reputation: 3365

You can use the @Lob annotation on a field, and your JPA provider will figure out the rest. I have used it for

For example:

@Entity
public class TextArticle{

    private Date creationDate;

    @Lob
    private String textContent;

    ...
}

And then later, use it as a String.

EntityManager em;
em.persist(new TextArticle(date, textContent));

If you would prefer to use a BLOB instead of a CLOB, try this:

@Entity
public class TextArticle{

    private Date creationDate;

    @Lob
    private byte[] textBytes;

    ...
}

Check out the Hibernate Documentation

Upvotes: 3

Related Questions