Hi All,
we want to lazily load a column from database. As that column is a blob object,we don't want to load that heavy blob object in particular usecases.
We are using Oracle 10g ,Hibernate 3.1 and Spring 1.2.6.
I have attached code for mapping blob object for AttachmentVO.
package com.fedbid.model.vo;
import java.io.Serializable;
import java.util.Date;
/**@author Hibernate CodeGenerator
* @hibernate.class table="ATTACHMENT"
*
* */
public class AttachmentVO implements Serializable{
/** identifier field */
private Integer attachmentId;
/** identifier field */
private Integer auctionId;
/** persistent field */
private byte[] attachment;
/** default constructor */
public AttachmentVO() {
}
/**
* @return Returns the attachment.
* @hibernate.property column="ATTACHMENT" type="com.fedbid.model.BinaryBlobType"
*/
public byte[] getAttachment() {
return attachment;
}
/**
* @param attachment
* The attachment to set.
*/
public void setAttachment(byte[] attachment) {
this.attachment = attachment;
}
/**
* @return Returns the attachmentId.
* @hibernate.id column="ATTACHMENT_ID"generator-class="sequence"
* @hibernate.generator-param name="sequence" value="ATTACHMENT_seq"
*/
public Integer getAttachmentId() {
return attachmentId;
}
/**
* @param attachmentId
* The attachmentId to set.
*/
public void setAttachmentId(Integer attachmentId) {
this.attachmentId = attachmentId;
}
/**
* @return Returns the auctionId.
* @hibernate.property column="AUCTION_ID"
*/
public Integer getAuctionId() {
return auctionId;
}
}
BinaryBlobUserType Class:
/**
*
*/
package com.fedbid.model;
import java.io.Serializable;
import java.sql.Blob;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;
/**
*
* Utility method for storing and retrieving blob data using hiberante. This class is used in
* AttachmentVO : @hibernate.property column="ATTACHMENT" type="com.fedbid.model.BinaryBlobType"
* for byte[] getAttachment() method.
*
*/
public class BinaryBlobType implements UserType {
public int[] sqlTypes() {
return new int[] { Types.BLOB };
}
public Class returnedClass() {
return byte[].class;
}
public boolean equals(Object x, Object y) {
return (x == y)
|| (x != null && y != null && java.util.Arrays.equals(
(byte[]) x, (byte[]) y));
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
throws HibernateException, SQLException {
Blob blob = rs.getBlob(names[0]);
return blob.getBytes(1, (int) blob.length());
}
public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException {
st.setBytes(index, (byte[]) value);
}
public Object deepCopy(Object value) {
if (value == null)
return null;
byte[] bytes = (byte[]) value;
byte[] result = new byte[bytes.length];
System.arraycopy(bytes, 0, result, 0, bytes.length);
return result;
}
public boolean isMutable() {
return true;
}
public int hashCode(Object arg0) throws HibernateException {
// TODO Auto-generated method stub
return 0;
}
public Serializable disassemble(Object arg0) throws HibernateException {
// TODO Auto-generated method stub
return null;
}
public Object assemble(Serializable arg0, Object arg1)
throws HibernateException {
// TODO Auto-generated method stub
return null;
}
public Object replace(Object arg0, Object arg1, Object arg2)
throws HibernateException {
// TODO Auto-generated method stub
return null;
}
}
I really appreciate for any suggestions or help.
Thanks,
Santhosh.
|