byte[], Byte[]
char[], String, Character[]
To use this feature just need to use the @javax.persistence.Lob annotation. 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.
@Entity
public class BlobEntity implements Serializable
{
private long id;
private Blob blobby;
private Clob clobby;
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
@Lob @Basic(fetch = FetchType.EAGER)
public Blob getBlobby()
{
return blobby;
}
public void setBlobby(Blob blobby)
{
this.blobby = blobby;
}
@Lob @Basic(fetch = FetchType.EAGER)
public Clob getClobby()
{
return clobby;
}
public void setClobby(Clob clobby)
{
this.clobby = clobby;
}
}
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.
byte[]to Clob/Blob
@Entity
public class BlobEntity2 implements Serializable
{
private long id;
private byte[] blobby;
private String clobby;
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
@Lob @Basic(fetch = FetchType.EAGER)
public byte[] getBlobby()
{
return blobby;
}
public void setBlobby(byte[] blobby)
{
this.blobby = blobby;
}
@Lob @Basic(fetch = FetchType.EAGER)
public String getClobby()
{
return clobby;
}
public void setClobby(String clobby)
{
this.clobby = clobby;
}
}
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