Hi, I'm having a similar problem. I need to get the next Id for the object I'm saving and use it to create a generated login, i.e: login = user.getFirstName() + user.getUserId()
I've used the code above to get me the next user id but when I call getHibernateTemplate().save(user); the userId is incremented again with the next userId. Here is a sample of the code I'm trying to use to do this:
Code:
Integer userId = (Integer) ((EntityPersister)getSessionFactory().getClassMetadata(user.getClass())).getIdentifierGenerator().generate((SessionImplementor)getSession(), user); //Id here = 1
user.setUserId(userId);
user.setLogin(user.getFirstName() + userId);
return getHibernateTemplate().save(user);//after saving Id here = 2
Note that I'm using the Spring 2.5.6 HibernateTemplate class to call Hibernate