[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4459?page=c...
]
Piotr Findeisen commented on HHH-4459:
--------------------------------------
This patch resolved the problem for me (i'm using Hibernate 3.5.3):
{noformat}
diff --git a/org/hibernate/type/ComponentType.java
b/org/hibernate/type/ComponentType.java
index 3bb56ef..98165e8 100644
--- a/org/hibernate/type/ComponentType.java
+++ b/org/hibernate/type/ComponentType.java
@@ -378,6 +378,8 @@ public class ComponentType extends AbstractType implements
AbstractComponentType
public Object[] getPropertyValues(Object component, EntityMode entityMode)
throws HibernateException {
+ if (component instanceof Object[])
+ return (Object[]) component;
return tuplizerMapping.getTuplizer( entityMode ).getPropertyValues(
component );
}
{noformat}
Query with Composite Primary Key parameter crashes when query cache
is on
-------------------------------------------------------------------------
Key: HHH-4459
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4459
Project: Hibernate Core
Issue Type: Bug
Components: caching (L2)
Affects Versions: 3.3.2
Environment: Hibernate Core 3.3.2.GA, MySQL and H2
Reporter: Karol Bienkowski
Attachments: HHH-4459.ZIP
I have an entity with a composite identifier (primary key) annotated with EmbeddedId:
@Embeddable
public class CompositeKey implements Serializable {
(...)
}
@Entity
public class EntityWithCompositeKey {
@EmbeddedId
public CompositeKey pk;
(...)
}
When executing query ...
FROM EntityWithCompositeKey e WHERE e.pk = :pk
... where ":pk" is bound to an instance of CompositeKey ...
query.setParamter("pk", new CompositeKey(..))
... I get the following exception:
javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not
get a field value by reflection getter of hhhxxxx.CompositeKey.a
at
org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:76)
at hhhxxxx.HHHHxxxxTest.testGetByCompositeId(HHHHxxxxTest.java:46)
(...)
Caused by: org.hibernate.PropertyAccessException: could not get a field value by
reflection getter of hhhxxxx.CompositeKey.a
at
org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:58)
at
org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:87)
at
org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:93)
at
org.hibernate.tuple.component.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:109)
at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:376)
at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:194)
at org.hibernate.engine.TypedValue.hashCode(TypedValue.java:66)
at java.util.HashMap$Entry.hashCode(Unknown Source)
at java.util.AbstractMap.hashCode(Unknown Source)
at org.hibernate.cache.QueryKey.generateHashCode(QueryKey.java:196)
at org.hibernate.cache.QueryKey.<init>(QueryKey.java:173)
at org.hibernate.cache.QueryKey.generateQueryKey(QueryKey.java:128)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2144)
at org.hibernate.loader.Loader.list(Loader.java:2121)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:67)
... 21 more
Caused by: java.lang.IllegalArgumentException: Can not set int field
hhhxxxx.CompositeKey.a to [Ljava.lang.Object;
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(Unknown Source)
at sun.reflect.UnsafeIntegerFieldAccessorImpl.getInt(Unknown Source)
at sun.reflect.UnsafeIntegerFieldAccessorImpl.get(Unknown Source)
at java.lang.reflect.Field.get(Unknown Source)
at
org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:55)
... 40 more
It used to work on 3.3.1.GA but fails in 3.3.2.GA. Turning off query cache works.
The direct reason for the error is that TypedValue.value is an Object[] but
ComponentType.getHashCode() expects TypedValue.value to be of CompositeKey type.
I'll attach the working test case replicating the issue in a moment.
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira