|
4 | 4 | */
|
5 | 5 | package org.hibernate.tool.schema.internal;
|
6 | 6 |
|
7 |
| -import org.hibernate.HibernateException; |
8 | 7 | import org.hibernate.boot.Metadata;
|
| 8 | +import org.hibernate.boot.model.naming.NamingHelper; |
9 | 9 | import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
10 | 10 | import org.hibernate.dialect.Dialect;
|
11 | 11 | import org.hibernate.engine.jdbc.Size;
|
|
15 | 15 | import org.hibernate.type.descriptor.jdbc.JdbcType;
|
16 | 16 |
|
17 | 17 | import java.math.BigInteger;
|
18 |
| -import java.security.MessageDigest; |
19 |
| -import java.security.NoSuchAlgorithmException; |
20 | 18 | import java.util.Arrays;
|
21 | 19 | import java.util.Locale;
|
22 | 20 |
|
@@ -129,7 +127,7 @@ private static void appendConstraints(
|
129 | 127 | Dialect dialect,
|
130 | 128 | SqlStringGenerationContext context) {
|
131 | 129 | if ( column.isUnique() && !table.isPrimaryKey( column ) ) {
|
132 |
| - String uniqueKeyName = column.getUniqueKeyName(); |
| 130 | + final String uniqueKeyName = column.getUniqueKeyName(); |
133 | 131 | final String keyName = uniqueKeyName == null
|
134 | 132 | // fallback in case the ImplicitNamingStrategy name was not assigned
|
135 | 133 | // (we don't have access to the ImplicitNamingStrategy here)
|
@@ -296,35 +294,8 @@ private static String generateName(String prefix, Table table, Column... columns
|
296 | 294 | final String columnName = column == null ? "" : column.getName();
|
297 | 295 | builder.append( "column`" ).append( columnName ).append( "`" );
|
298 | 296 | }
|
299 |
| - return prefix + hashedName( builder.toString() ); |
| 297 | + final byte[] hashed = NamingHelper.hash( builder.toString().getBytes() ); |
| 298 | + return prefix + new BigInteger( 1, hashed ).toString( 35 ); |
300 | 299 | }
|
301 | 300 |
|
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 |
| - } |
330 | 301 | }
|
0 commit comments