1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| package util;
import java.io.Serializable;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.id.IdentifierGenerator;
public class GenerateId implements IdentifierGenerator{
public Serializable generate(SessionImplementor arg0, Object arg1) throws HibernateException {
Long a = null;
//Session session = HibernateUtil.getSessionFactory().getCurrentSession();
//session.beginTransaction();
/*a = (Long)session.createSQLQuery("select max(ADRESSE_ID) as test from ADRESSE adr")
.addScalar("test",Hibernate.LONG).uniqueResult();
*/
a = (Long)arg0.getFactory().getCurrentSession().createSQLQuery("select max(ADRESSE_ID) as test from ADRESSE adr")
.addScalar("test",Hibernate.LONG)
.uniqueResult();
a = new Long(a.longValue() + 1);
System.out.println("Long a = " + a.longValue());
//session.getTransaction().commit();
return a;
}
} |
Partager