2 Replies Latest reply on Sep 17, 2012 2:56 PM by ctomc

    Hibernate 4 - session.getBatcher() - How to work around?

    pugsherpa

      We have a custom sequence generator that followed the old model

       

      {code}

      public Serializable generate(SessionImplementor session, Object obj)

          throws HibernateException {

       

              try {

       

                  PreparedStatement st = session.getBatcher().prepareSelectStatement(sql);

                  try {

                      ResultSet rs = st.executeQuery();

                      try {

                          rs.next();

                          Serializable result = IdentifierGeneratorFactory.get(

                                  rs, identifierType

                              );

                          if ( log.isDebugEnabled() ) {

                              log.debug("Sequence identifier generated: " + result);

                          }

                          return result;

                      }

                      finally {

                          rs.close();

                      }

                  }

                  finally {

                      session.getBatcher().closeStatement(st);

                  }

       

              }

              catch (SQLException sqle) {

                  throw JDBCExceptionHelper.convert(

                          session.getFactory().getSQLExceptionConverter(),

                          sqle,

                          "could not get next sequence value",

                          sql

                      );

              }

       

          }

      {code}

       

      However, SessionImplementor method getBatcher() doesn't exist anymore in Hibernate 4 and I haven't been able to find what the work-around solution would be.

       

      Does anyone have any idea?