title: Unexpected ArrayIndexOutOfBoundsException in Hibernate UUIDTypeDescriptor$ToBytesTransformer.parse() method
body: <p>I'm using Java 6 and hibernate-core-4.0.0.final.jar with hibernate-commons-annotations-4.0.1.Final.jar and hibernate-jpa-2.0-api-1.0.1.Final.jar</p>
  
  <p>I have an entity with a java.util.UUID column as PK. the PK is not automatically generated by hibernate. Rather I set the id of the record to be created or updated. I get the id from the request data coming to our server. Let's assume an app that uses our API pushes a record with a uuid as string. on our server we persist that record.</p>
  
  <p>The problem is that I get an ArrayOutOfBoundException when calling merge. This happens only sometimes and I have no idea what is involved. I've been trying to reproduce the bug but no success yet. </p>
  
  <p>Here's the stack trace that I see in our server log. The line in our application is </p>
  
  <pre><code>getEntityManager().merge(record)
  </code></pre>
  
  <p>The stackTrace follows:</p>
  
  <pre><code>    java.lang.ArrayIndexOutOfBoundsException
  at java.lang.System.arraycopy(Native Method) [rt.jar:1.6.0_31]
  at org.hibernate.type.descriptor.java.UUIDTypeDescriptor$ToBytesTransformer.parse(UUIDTypeDescriptor.java:128) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.type.descriptor.java.UUIDTypeDescriptor.wrap(UUIDTypeDescriptor.java:80) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.type.descriptor.java.UUIDTypeDescriptor.wrap(UUIDTypeDescriptor.java:37) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.type.descriptor.sql.VarbinaryTypeDescriptor$2.doExtract(VarbinaryTypeDescriptor.java:67) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:65) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:269) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:265) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:357) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:702) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:635) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.loader.Loader.doQuery(Loader.java:856) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.loader.Loader.loadEntity(Loader.java:2058) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:82) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:72) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3697) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:439) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:420) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:204) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:251) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:148) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:954) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:903) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:610) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.type.EntityType.resolve(EntityType.java:438) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:150) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1006) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.loader.Loader.doQuery(Loader.java:883) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.loader.Loader.loadEntity(Loader.java:2058) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:82) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:72) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3697) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:439) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:420) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:204) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:251) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:148) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:954) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.internal.SessionImpl.get(SessionImpl.java:870) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:460) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:256) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:86) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:781) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:766) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:770) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:867) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
  at org.jboss.as.jpa.container.AbstractEntityManager.merge(AbstractEntityManager.java:548) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
  </code></pre>
  
  <p>Thanks in advance for any help. </p>