I am using Hibernate Annotations for the first time in my web application. In my bean, what type what annotations should I use to persist files uploaded by users?
+1
A:
I assume that you're using the JPA annotations. If so, you'll want to use the @Lob
annotation for large data sets. See this page for an example.
This page lists a little more information specific to Hibernate JPA. Of interest:
@Lob indicates that the property should be persisted in a Blob or a Clob depending on the property type: java.sql.Clob, Character[], char[] and java.lang.String will be persisted in a Clob. java.sql.Blob, Byte[], byte[] and serializable type will be persisted in a Blob.
Kaleb Brasee
2010-01-21 20:38:17
There are actually two fields - one specifically for images file, the other for any arbitrary file. These should both be handled as byte[] I presume?
lupefiasco
2010-01-21 20:42:38
You could do byte[], or if your fields are serializable, you could directly define them as that serializable type -- see here for an example: http://www.java2s.com/Tutorial/Java/0355__JPA/MapSerializableEntityToLob.htm
Kaleb Brasee
2010-01-21 21:16:24