Note that there are some explanatory texts on larger screens.

plurals
  1. POSave file in mysql database using Hibernate
    primarykey
    data
    text
    <p>I'm trying to figure out the 'correct', failsafe way to save/retrieve files in a mysql database using Hibernate. The solution has to work with files that are quite large, so minimizing the memory footprint would be important.</p> <p>My solution, so far:</p> <p>A model class containing a java.sql.Blob field, the getter annotated with "@Lob".</p> <pre><code>public static void main(String[] args) { DAOFactory factory = DAOFactory.getFactory(); IResultExtraDAO resultExtraDAO = factory.getResultExtraDAO(); factory.getResultExtraDAO().beginTransaction(); ResultExtra resultExtra = new ResultExtra(); LobHelper lh = HibernateUtil.getSession().getLobHelper(); try { File file = new File("/3030.jpg"); FileInputStream fis = new FileInputStream(file); Blob b = lh.createBlob(fis, fis.available()); resultExtra.setFile(b); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } resultExtraDAO.save(resultExtra); factory.getResultExtraDAO().commitTransaction(); } </code></pre> <p>Is this the correct way to do it? Whould there be a risk of running out of memmory if there are manny simultanious uploads and/or large files? Is there another solution that would be better?</p> <p>Also, I'm using the '<a href="http://community.jboss.org/wiki/GenericDataAccessObjects" rel="nofollow">Generic Data Access Object</a>' pattern encapsule hibernate, so I don't like accessing the HibernateUtil directly as I do here, but so far I haven't figured out a good generic way to access it. Suggestions are welcome.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload