I'm implementing a custom Id generator for Hibernate. In my generate-method I need to read from another table and modify data on it. That's (about) the way I would do it:
session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
Criteria criteria = session.createCriteria(...)...;
criteria.uniqueResult();
...
session.save(...);
transaction.commit();
That works fine, but how can I use it in my Generator. The generate-method gets a SessionImplementor
, not a Session
. How can I persist an entity with it?
public class MyGenerator implements IdentifierGenerator
{
@Override
public Serializable generate(final SessionImplementor session, final Object object) throws HibernateException
{
???
}
}
Any ideas?
It turned out to be quite simple:
Session session = ( Session ) sessionImplementor;