Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>We are doing exactly that with the "original" Java Hibernate3. You just map a byte array property of your persistable class to an column of Type "image".</p> <pre><code>package com.hibernate.pdf.sample; public class TPDFDocument implements java.io.Serializable { private Integer pdfDocumentId; private byte[] document; public Integer getPdfDocumentId() { return this.pdfDocumentId; } public void setPdfDocumentId(Integer pdfDocumentId) { this.pdfDocumentId = pdfDocumentId; } public byte[] getDocument() { return this.document; } public void setDocument(byte[] document) { this.document = document; } } </code></pre> <p>Hibernate Mapping:</p> <pre><code>&lt;hibernate-mapping&gt; &lt;class name="com.hibernate.pdf.sample.TPDFDocument" table="T_PDFDocument"&gt; &lt;id name="pdfDocumentId" type="integer"&gt; &lt;column name="pdfDocumentId" /&gt; &lt;generator class="identity" /&gt; &lt;/id&gt; &lt;property name="document" type="binary"&gt; &lt;column name="document" not-null="true" /&gt; &lt;/property&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>Table creation:</p> <pre><code>CREATE TABLE [dbo].[T_PDFDocument]( [pdfDocumentId] [int] IDENTITY(1,1) NOT NULL, [document] [image] NOT NULL, CONSTRAINT [PK_PDFDocument] PRIMARY KEY CLUSTERED ( [pdfDocumentId] ASC ) </code></pre> <p>All you have to do is to read the documents raw bytes into the array and persist it. In our situation the documents will get hardly larger than 1MB , so putting the whole thing into the byte-array won't cause performance issues. Maybe this solution isn't feasable for very large documents.</p> <p>I guess with NHibernate implementation and C# the solution will look very similar.</p>
 

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