We have a problem where we need to keep the copy of an input file in DB(regulatory purpos开发者_StackOverflow社区es). 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 ?
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
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.
精彩评论