Version 3

    java.sql.Blob and Clob support

    The EJB 3.0 specification has support for Blob and Clob types.  You just need to use the @javax.ejb.Lob.  The Lob annotation is an

    encapsulation of what type of lob you want.  Below is an example of defining fields in an entity that are blobs or clobs.


    public class BlobEntity implements Serializable
       private long id;
       private Blob blobby;
       private Clob clobby;
       @Id(generate = GeneratorType.IDENTITY)
       public long getId()
          return id;
       public void setId(long id)
 = id;
       public Blob getBlobby()
          return blobby;
       public void setBlobby(Blob blobby)
          this.blobby = blobby;
       @Lob(type = LobType.CLOB, fetch=FetchType.EAGER)
       public Clob getClobby()
          return clobby;
       public void setClobby(Clob clobby)
          this.clobby = clobby;


    Working with Blobs and Clobs

    Open up LobTesterBean and look for the create() method.  JBoss EJB3

    is built on top of the Hibernate persistence engine.  Hibernate has some helper methods for creating blobs and clobs that LobTesterBean



    Blob Creation

    org.hibernate.Hibernate.createBlob(byte[] bytes)
    org.hibernate.Hibernate.createBlob(InputStream stream, int length)
    org.hibernate.Hibernate.createBlob(InputStream stream)



    Clob Creation

    org.hibernate.Hibernate.createClob(String string)
    org.hibernate.Hibernate.createClob(Reader reader, int length)


    Blobs and clobs must only be accessed within a transaction.  Blobs and clobs are also not serializable or detachable.


    Building and Running

    To build and run the example, make sure you have ejb3.deployer installed in JBoss 4.0.x and have JBoss running.  See the reference manual on how to install EJB 3.0.

    Unix:    $ export JBOSS_HOME=<where your jboss 4.0 distribution is>
    Windows: $ set JBOSS_HOME=<where your jboss 4.0 distribution is>
    $ ant
    $ ant run


    View the tables and rows

    You can view the tables created by JBoss by going to the Hypersonic SQL service, scrolling down to the startDatabaseManager button and clicking it.  A Hypersonic SQL window will be minimized, but you can open it up to look at the tables and do queries.