We are using hibernate mapping. In hibernate configuration file we have given type="blob" and pojo class getBlob and setBlob methods we have. Apart from this we need to have @lob right. what is equivalent for lob in hibernate mapping
@Override
public Hospital getHospital(long hospId, String hospitalName) {
Hospital hos= hibernateTemplate.find("from Hospital
hos where hos.id = ? and hos.name = ? ", hospId,hospitalName);
}
@Transactional
public void saveHospital(Hosipital hos) {
Blob blob = Hibernate.getLobCreator(hibernateTemplate.getSessionFactory().getCurrentSession()).createBlob(hos.getContent());
hos.setHospitalImage(blob);
hibernateTemplate.saveOrUpdate("Hospital", hos);
}
In my model I'm using the following:
The annotation
@Lob
indicates that it's a Lob column; the@Basic(fetch=FetchType.LAZY)
indicates to load the entity without loading the Lob in memory; you can access to the lob only when you really needUPDATE
Long time I don't use XML but if I'm not wrong you may use something like this:
UPDATE 2
I never used
hibernateTemplate
in any case also by using hibernateTemplate you can access to the hibernate session Usually I do the following:Save Blob method
GET BLOB METHOD
type is blob. it maps to hibernate pojo with Blob data type.Both will match and it saves your image as well.
In hbm.xml u
property name="contentualblob" type="blob"
Use the
basic
tag and add thelob
tag inside: