1

私のコントローラーのコード

FileInsertion fileInsertion = new FileInsertion();
FileUpload fileUpload = new FileUpload();
fileUpload.setFilename((InputStream) new ByteArrayInputStream(byteArray));
    //byteArray is the file converted into a byte[]
fileInsertion.insertFile(fileUpload);

    //the following happens in a separate method
trns = session.beginTransaction();
session.save(fileUpload);
session.getTransaction().commit();

Hibernateマッピングファイル

<hibernate-mapping>
    <class name="com.sort.process.FileUpload" table="fileupload">
        <meta attribute="class-description">
            This class contains the file upload detail. 
        </meta>
        <id name="Id" type="int" column="Id">
            <generator class="increment" />
        </id>

        <property name="filename">
            <column name="filename" />
        </property>
    </class>
</hibernate-mapping>

私の目的は、BLOBオブジェクトの代わりにdbテーブルにファイルを挿入することです。しかし、私はこれを手に入れています

Initial SessionFactory creation failed.org.hibernate.MappingException: Could not determine type for: java.io.InputStream, at table: fileupload, for columns: [org.hibernate.mapping.Column(filename)]

ByteArrayInputStreamの代わりに上記を使用してみましたInputStreamが、無駄でした。誰かがコードの私の間違いを教えてもらえますか?
前もって感謝します

4

1 に答える 1

1

モデルで byte[] を直接使用すると、うまくいくはずです。すなわち、fileUpload.setFilename(byteArray)

意味のある名前を使用することをお勧めします。fileUpload.getFileName()生データではなく、ファイル名が返されることを期待する人もいるかもしれません。

于 2012-12-19T12:42:35.417 に答える