Results 1 to 9 of 9

Thread: MySQL Schema on 5.0.67

  1. #1
    Join Date
    Apr 2008
    Posts
    9

    Default MySQL Schema on 5.0.67

    Hi,
    i use MySQL Server 5.0.67 on ubuntu. When i create springbatch schema i got:

    ERROR 1071 (42000) at line 3: Specified key was too long; max key length is 767 bytes

    any ideas ?

  2. #2
    Join Date
    Apr 2008
    Posts
    9

    Default MySQL bug

    At the momen i removed only the constraint on BATCH_JOB_INSTANCE:
    Code:
    constraint JOB_INST_UN unique (JOB_NAME, JOB_KEY)
    Seems a bug on mysql.

    If anyone have other ideas i appreciate.
    Thanks

  3. #3
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    You can remove the constraint as a workaround. I'd be interested to see how to make it work on MySQL though. Can someone raise a JIRA if they know the answer...?

  4. #4
    Join Date
    Apr 2008
    Posts
    9

    Default

    Seems a very long term bug (since 2004) i think the only way to have it working on mysql is to change constraint key to a lower value.
    I've already tried to use latin1 encoding instead of UTF-8 (that use 3 bytes for a char) without success.
    I don't already know spring-batch so deep to understand why the BATCH_JOB_INSTANCE should have a JOB_KEY of 2500 indexed.

  5. #5
    Join Date
    Apr 2008
    Posts
    9

    Default

    Ok, now i understand JOB_KEY need. But why store all the parameters and not a md5 hash of the same string that will use at maximum a varchar of 32?

  6. #6
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    Excellent idea. http://jira.springframework.org/browse/BATCH-1146. To do that we have to pick a standard encoding from the String to bytes[]. I was going to go with UTF-8. Anyone know of a platform where that wouldn't be available?

  7. #7
    Join Date
    Apr 2008
    Posts
    9

    Default

    I found this code that use java.security.MessageDigest to perform MD5

    Code:
    import java.io.UnsupportedEncodingException;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
     
    public class MD5 {
     
    	private static String convertToHex(byte[] data) {
            StringBuffer buf = new StringBuffer();
            for (int i = 0; i < data.length; i++) {
            	int halfbyte = (data[i] >>> 4) & 0x0F;
            	int two_halfs = 0;
            	do {
    	        	if ((0 <= halfbyte) && (halfbyte <= 9))
    	                buf.append((char) ('0' + halfbyte));
    	            else
    	            	buf.append((char) ('a' + (halfbyte - 10)));
    	        	halfbyte = data[i] & 0x0F;
            	} while(two_halfs++ < 1);
            }
            return buf.toString();
        }
     
    	public static String MD5(String text) 
    	throws NoSuchAlgorithmException, UnsupportedEncodingException  {
    		MessageDigest md;
    		md = MessageDigest.getInstance("MD5");
    		byte[] md5hash = new byte[32];
    		md.update(text.getBytes("iso-8859-1"), 0, text.length());
    		md5hash = md.digest();
    		return convertToHex(md5hash);
    	}
    }
    Bye and thanks for the ISSUE

  8. #8
    Join Date
    Apr 2008
    Posts
    9

    Default MD5 patch

    Hi,
    for convenience i made a little patch with the modified code (seem pass all related tests)
    bye
    Attached Files Attached Files

  9. #9
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    Thanks for the patch (but I already implemented it in two lines using MessageDigest and BigInteger with String.format). I'm just waiting for feedback on the encoding.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •