Skip to content

Commit b77893f

Browse files
committed
use our own md5 impl, since some tools detect and warn about use of MessageDigest
1 parent 2981a52 commit b77893f

File tree

1 file changed

+4
-33
lines changed

1 file changed

+4
-33
lines changed

hibernate-core/src/main/java/org/hibernate/tool/schema/internal/ColumnDefinitions.java

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*/
55
package org.hibernate.tool.schema.internal;
66

7-
import org.hibernate.HibernateException;
87
import org.hibernate.boot.Metadata;
8+
import org.hibernate.boot.model.naming.NamingHelper;
99
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
1010
import org.hibernate.dialect.Dialect;
1111
import org.hibernate.engine.jdbc.Size;
@@ -15,8 +15,6 @@
1515
import org.hibernate.type.descriptor.jdbc.JdbcType;
1616

1717
import java.math.BigInteger;
18-
import java.security.MessageDigest;
19-
import java.security.NoSuchAlgorithmException;
2018
import java.util.Arrays;
2119
import java.util.Locale;
2220

@@ -129,7 +127,7 @@ private static void appendConstraints(
129127
Dialect dialect,
130128
SqlStringGenerationContext context) {
131129
if ( column.isUnique() && !table.isPrimaryKey( column ) ) {
132-
String uniqueKeyName = column.getUniqueKeyName();
130+
final String uniqueKeyName = column.getUniqueKeyName();
133131
final String keyName = uniqueKeyName == null
134132
// fallback in case the ImplicitNamingStrategy name was not assigned
135133
// (we don't have access to the ImplicitNamingStrategy here)
@@ -296,35 +294,8 @@ private static String generateName(String prefix, Table table, Column... columns
296294
final String columnName = column == null ? "" : column.getName();
297295
builder.append( "column`" ).append( columnName ).append( "`" );
298296
}
299-
return prefix + hashedName( builder.toString() );
297+
final byte[] hashed = NamingHelper.hash( builder.toString().getBytes() );
298+
return prefix + new BigInteger( 1, hashed ).toString( 35 );
300299
}
301300

302-
/**
303-
* Hash a constraint name using MD5. Convert the MD5 digest to base 35
304-
* (full alphanumeric), guaranteeing
305-
* that the length of the name will always be smaller than the 30
306-
* character identifier restriction enforced by a few dialects.
307-
*
308-
* @param name The name to be hashed.
309-
* @return String The hashed name.
310-
*
311-
* @deprecated Only used from deprecated methods
312-
*/
313-
@Deprecated(since = "6.5", forRemoval = true)
314-
private static String hashedName(String name) {
315-
try {
316-
final var messageDigest = MessageDigest.getInstance( "MD5" );
317-
messageDigest.reset();
318-
messageDigest.update( name.getBytes() );
319-
final byte[] digest = messageDigest.digest();
320-
final var bigInt = new BigInteger( 1, digest );
321-
// By converting to base 35 (full alphanumeric), we guarantee
322-
// that the length of the name will always be smaller than the 30
323-
// character identifier restriction enforced by a few dialects.
324-
return bigInt.toString( 35 );
325-
}
326-
catch ( NoSuchAlgorithmException e ) {
327-
throw new HibernateException( "Unable to generate a hashed Constraint name", e );
328-
}
329-
}
330301
}

0 commit comments

Comments
 (0)