Hi, all!
I am currently worked on an project that saves binary files to DB (PostgreSQL 8.3, Hibernate 3.5).
I have next code:
Domain object:
Code:
@Entity
@Table(name="ITEM")
public class Item {
@Id @GeneratedValue
@Column(name="ITEM_ID")
private Long id = null;
@Lob
@Column(name="BLOB_LOCATOR")
private Blob blobLocator;
public Item() {}
public Long getId() {
return id;
}
public Blob getBlobLocator() {
return blobLocator;
}
public void setBlobLocator(Blob blobLocator) {
this.blobLocator = blobLocator;
}
}
Snippet from DAO class:
Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Item item = new Item();
item.setBlobLocator(Hibernate.createBlob(new byte[100], session));
session.saveOrUpdate(item);
session.getTransaction().commit();
When i try run it, throws exception:
Code:
Exception in thread "main" java.lang.ClassCastException: $Proxy9 cannot be cast to org.hibernate.engine.jdbc.LobCreationContext
at org.hibernate.Hibernate.getLobCreator(Hibernate.java:420)
at org.hibernate.Hibernate.getLobCreator(Hibernate.java:416)
at org.hibernate.Hibernate.createBlob(Hibernate.java:412)
If instead createBlob(byte[], Session) used createBlob(byte[]), it's work fine! But method createBlob(byte[]) deprecated in Hibernate 3.5.
When instead HibernateUtil.getSessionFactory().openSession() i use HibernateUtil.getSessionFactory().getCurrentSession(), that's work fine.
Everybody know how to solve this problem? Thank you for you help!