HHH-9271 - IdentityGenerator broken with quoted identifiers
Use dialect for verifying quoting
This commit is contained in:
parent
573518cfc9
commit
565318067b
|
@ -61,7 +61,8 @@ public class GetGeneratedKeysDelegate
|
||||||
return IdentifierGeneratorHelper.getGeneratedIdentity(
|
return IdentifierGeneratorHelper.getGeneratedIdentity(
|
||||||
rs,
|
rs,
|
||||||
persister.getRootTableKeyColumnNames()[0],
|
persister.getRootTableKeyColumnNames()[0],
|
||||||
persister.getIdentifierType()
|
persister.getIdentifierType(),
|
||||||
|
session.getFactory().getDialect()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|
|
@ -15,9 +15,10 @@ import java.sql.ResultSetMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.internal.CoreLogging;
|
import org.hibernate.internal.CoreLogging;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.type.CustomType;
|
import org.hibernate.type.CustomType;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
|
|
||||||
|
@ -61,18 +62,19 @@ public final class IdentifierGeneratorHelper {
|
||||||
* @param rs The result set from which to extract the the generated identity.
|
* @param rs The result set from which to extract the the generated identity.
|
||||||
* @param identifier The name of the identifier column
|
* @param identifier The name of the identifier column
|
||||||
* @param type The expected type mapping for the identity value.
|
* @param type The expected type mapping for the identity value.
|
||||||
|
* @param dialect The current database dialect.
|
||||||
*
|
*
|
||||||
* @return The generated identity value
|
* @return The generated identity value
|
||||||
*
|
*
|
||||||
* @throws SQLException Can be thrown while accessing the result set
|
* @throws SQLException Can be thrown while accessing the result set
|
||||||
* @throws HibernateException Indicates a problem reading back a generated identity value.
|
* @throws HibernateException Indicates a problem reading back a generated identity value.
|
||||||
*/
|
*/
|
||||||
public static Serializable getGeneratedIdentity(ResultSet rs, String identifier, Type type)
|
public static Serializable getGeneratedIdentity(ResultSet rs, String identifier, Type type, Dialect dialect)
|
||||||
throws SQLException, HibernateException {
|
throws SQLException, HibernateException {
|
||||||
if ( !rs.next() ) {
|
if ( !rs.next() ) {
|
||||||
throw new HibernateException( "The database returned no natively generated identity value" );
|
throw new HibernateException( "The database returned no natively generated identity value" );
|
||||||
}
|
}
|
||||||
final Serializable id = get( rs, identifier, type );
|
final Serializable id = get( rs, identifier, type, dialect );
|
||||||
LOG.debugf( "Natively generated identity: %s", id );
|
LOG.debugf( "Natively generated identity: %s", id );
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -84,13 +86,14 @@ public final class IdentifierGeneratorHelper {
|
||||||
* @param rs The result set from which to extract the value.
|
* @param rs The result set from which to extract the value.
|
||||||
* @param identifier The name of the identifier column
|
* @param identifier The name of the identifier column
|
||||||
* @param type The expected type of the value.
|
* @param type The expected type of the value.
|
||||||
|
* @param dialect The current database dialect.
|
||||||
*
|
*
|
||||||
* @return The extracted value.
|
* @return The extracted value.
|
||||||
*
|
*
|
||||||
* @throws SQLException Indicates problems access the result set
|
* @throws SQLException Indicates problems access the result set
|
||||||
* @throws IdentifierGenerationException Indicates an unknown type.
|
* @throws IdentifierGenerationException Indicates an unknown type.
|
||||||
*/
|
*/
|
||||||
public static Serializable get(ResultSet rs, String identifier, Type type)
|
public static Serializable get(ResultSet rs, String identifier, Type type, Dialect dialect)
|
||||||
throws SQLException, IdentifierGenerationException {
|
throws SQLException, IdentifierGenerationException {
|
||||||
if ( ResultSetIdentifierConsumer.class.isInstance( type ) ) {
|
if ( ResultSetIdentifierConsumer.class.isInstance( type ) ) {
|
||||||
return ( (ResultSetIdentifierConsumer) type ).consumeIdentifier( rs );
|
return ( (ResultSetIdentifierConsumer) type ).consumeIdentifier( rs );
|
||||||
|
@ -142,8 +145,8 @@ public final class IdentifierGeneratorHelper {
|
||||||
return extractIdentifier( rs, identifier, type, clazz );
|
return extractIdentifier( rs, identifier, type, clazz );
|
||||||
}
|
}
|
||||||
catch (SQLException e) {
|
catch (SQLException e) {
|
||||||
if(Identifier.isQuoted( identifier )) {
|
if ( StringHelper.isQuoted( identifier, dialect ) ) {
|
||||||
return extractIdentifier( rs, Identifier.toIdentifier( identifier).getText(), type, clazz );
|
return extractIdentifier( rs, StringHelper.unquote( identifier, dialect ), type, clazz );
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,8 @@ public class IdentityGenerator extends AbstractPostInsertGenerator {
|
||||||
return IdentifierGeneratorHelper.getGeneratedIdentity(
|
return IdentifierGeneratorHelper.getGeneratedIdentity(
|
||||||
rs,
|
rs,
|
||||||
persister.getRootTableKeyColumnNames()[0],
|
persister.getRootTableKeyColumnNames()[0],
|
||||||
persister.getIdentifierType()
|
persister.getIdentifierType(),
|
||||||
|
session.getFactory().getDialect()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
@ -138,7 +139,8 @@ public class IdentityGenerator extends AbstractPostInsertGenerator {
|
||||||
return IdentifierGeneratorHelper.getGeneratedIdentity(
|
return IdentifierGeneratorHelper.getGeneratedIdentity(
|
||||||
rs,
|
rs,
|
||||||
persister.getRootTableKeyColumnNames()[0],
|
persister.getRootTableKeyColumnNames()[0],
|
||||||
persister.getIdentifierType()
|
persister.getIdentifierType(),
|
||||||
|
session.getFactory().getDialect()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,8 @@ public class SequenceIdentityGenerator
|
||||||
return IdentifierGeneratorHelper.getGeneratedIdentity(
|
return IdentifierGeneratorHelper.getGeneratedIdentity(
|
||||||
insert.getGeneratedKeys(),
|
insert.getGeneratedKeys(),
|
||||||
getPersister().getRootTableKeyColumnNames()[0],
|
getPersister().getRootTableKeyColumnNames()[0],
|
||||||
getPersister().getIdentifierType()
|
getPersister().getIdentifierType(),
|
||||||
|
session.getFactory().getDialect()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue