Short node on (B)Lobs in Entity Beans

Have you ever thought about storing files in an Entity-Table, using the JPA? Well here is the solution:

@Entity
@Table(name = "histories")
@NamedQueries({
   @NamedQuery(name = History.FIND_ALL, query = "SELECT his FROM History his")
})
public class History extends EntityBase {
   public static final String FIND_ALL = "findAllHistories";
   @Temporal(TemporalType.TIMESTAMP)
   @Column(name="import_date")
   private Calendar importDate;
   ...
   /* BEGIN here */
   @Column(name="excel_file", length=20000000, columnDefinition="longblob")
   @Lob
   private byte[] excelFile;
   /* END here */
}

As usual the name in the Column annotation specifies the corresponding Column-name in the destination table.   The length property specifies the length of the Column. Actually, this is important, because the default length, provided by the JPA, is 4096, I think.  Obviously, the columnDefinition defines the datatype, which should be created from the JPA. At least add the @Lob annotation.

The resulting column in the database table should look smth like:

  • name: excel_file
  • nulls allowed: no
  • data type: LONGVARBINARY
  • column size: 2147483647
  • ...

No related posts.

Ähnliche Artikel bereitgestellt von Yet Another Related Posts Plugin.

  1. Noch keine Kommentare vorhanden.

  1. Noch keine TrackBacks.