FileDocCategorySizeDatePackage
GUIDGenerator.javaAPI DocHibernate 3.2.51462Tue Jun 21 23:19:34 BST 2005org.hibernate.id

GUIDGenerator

public class GUIDGenerator extends Object implements IdentifierGenerator
Generates string values using the SQL Server NEWID() function.
author
Joseph Fifield

Fields Summary
private static final Log
log
Constructors Summary
Methods Summary
public java.io.Serializablegenerate(org.hibernate.engine.SessionImplementor session, java.lang.Object obj)


	      
	  
		
		final String sql = session.getFactory().getDialect().getSelectGUIDString();
		try {
			PreparedStatement st = session.getBatcher().prepareSelectStatement(sql);
			try {
				ResultSet rs = st.executeQuery();
				final String result;
				try {
					rs.next();
					result = rs.getString(1);
				}
				finally {
					rs.close();
				}
				log.debug("GUID identifier generated: " + result);
				return result;
			}
			finally {
				session.getBatcher().closeStatement(st);
			}
		}
		catch (SQLException sqle) {
			throw JDBCExceptionHelper.convert(
					session.getFactory().getSQLExceptionConverter(),
					sqle,
					"could not retrieve GUID",
					sql
				);
		}