0

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?

martin
  • 2,150
  • 1
  • 34
  • 48

1 Answers1

0

It turned out to be quite simple:

Session session = ( Session ) sessionImplementor;
martin
  • 2,150
  • 1
  • 34
  • 48