我正在使用Java 6和hibernate-core-4.0.0.final.jar和hibernate-commons-annotations-4.0.1.Final.jar和hibernate-jpa-2.0-api-1.0.1.Final。罐
我有一个带有java.util.UUID列的实体作为PK。 PK不是由hibernate自动生成的。而是我设置要创建或更新的记录的ID。我从请求数据中获取id到我们的服务器。假设使用我们的API的应用程序使用uuid作为字符串推送记录。在我们的服务器上,我们坚持这一记录。
问题是我在调用merge时遇到了ArrayOutOfBoundException。这种情况有时只会发生,我不知道涉及到什么。我一直试图重现这个错误,但还没有成功。
这是我在服务器日志中看到的堆栈跟踪。我们申请中的行是
getEntityManager().merge(record)
stackTrace如下:
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]
提前感谢您的帮助。
答案 0 :(得分:0)
在从Long
(number(18)
)到java.util.UUID
(raw(16)
)的迁移过程中,我遇到了同样的错误。我用调试器代理启动Tomcat:
$ /opt/apache-tomcat-7.0.40/bin/catalina.sh jpda start
在Netbeans中下载Hibernate源代码,在UUIDTypeDescriptor$ToBytesTransformer.parse()
设置断点(访问源代码并双击该行)并使用Netbeans调试器附加到Tomcat。
我在value
中看到的内容:
public UUID parse(Object value) {
...
System.arraycopy( value, 0, msb, 0, 8 );
传递byte[4]
数组!我重新思考并意识到我忘记更改@Id
字段上的列名:
@Id
@NotNull
@Column(name = "UUID") // <-- here I fix name!
private UUID uuid;