Consider this simple Hibernate scenario:
session = getHibernateSession();
tx = session.beginTransaction();
SomeObject o = (SomeObject) session.get(SomeObject
Above solutions were not helpful for me and that is why I want to share my solution.
In my case, I was not using @Column annotation properly in one of my entity. I changed my code from
@Column(columnDefinition = "false")
private boolean isAvailable;
to
@Column(columnDefinition = "boolean default false")
private boolean isAvailable;
And it worked.
My create method in dao
public int create(Item item) {
Session session = sessionFactory.getCurrentSession();
try {
int savedId = (int) session.save(item);
return savedId;
} catch (Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
return 0; //==> handle in custom exception
}
}