[hibernate-issues] [Hibernate-JIRA] Created: (HHH-4459) Query with Composite Primary Key parameter crashes when query cache is on

Karol Bienkowski (JIRA) noreply at atlassian.com
Thu Sep 24 05:07:50 EDT 2009


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


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.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list