-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Exception when using query cache and ResultTransformer
PostPosted: Wed Mar 21, 2007 9:32 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Hi,

I am using the query cache on queries that uses a DISTINCT_ROOT_ENTITY ResultTransformer. If I use each of them separately everything is fine but together, there is the exception below

I am currently debugging hibernate to see what really happens. It seems to have something to deal with transformTuple on the ResultTransformer that converts an Object[1] to an Object. The error occurs because we try to invoke a getOid method on an Object[] which is not correct.

It seems to be a bug, I will investigate further but if somebody can confirm or not

Hibernate version: 3.2.2-ga

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
  <class name="ObjetTest" lazy="true">
    <id name="oid">
      <generator class="native"/>
    </id>
    <property name="code" type="java.lang.Integer"/>
    <property name="label" type="java.lang.String" length="40" unique-key="UQ_OBJTSTLBL_"/>
    <many-to-one name="parent" class="ObjetTest"/>
    <set name="children" table="OBJET_TEST_OBJET_TEST" cascade="all-delete-orphan" lazy="true">
      <key>
        <column name="CHILDREN__" />
      </key>
      <one-to-many class="ObjetTest" />
    </set>
  </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
        SessionFactory factory = new Configuration().configure().buildSessionFactory();
        Session session = factory.openSession();
        Transaction tx = session.beginTransaction();
        ObjetTest objetTest = new ObjetTest();
        objetTest.setCode(1);
        objetTest.setLabel("test");
        ObjetTest enfant = new ObjetTest();
        enfant.setCode(2);
        enfant.setLabel("child2");
        enfant.setParent(objetTest);
        objetTest.addChild(enfant);
        enfant = new ObjetTest();
        enfant.setCode(3);
        enfant.setLabel("child3");
        enfant.setParent(objetTest);
        objetTest.addChild(enfant);
        session.save(objetTest);
        Query query;
        query = session.createQuery("select obj from ObjetTest obj left outer join fetch obj.children as obj_0 order by obj.id asc");
        query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        query.setCacheable(true);
        for (Object object : query.list())
        {
            System.out.println(object);
        }
        tx.commit();
        session.close();

Full stack trace of any exception that occurs:
Code:
Hibernate: select gen_id( hibernate_sequence, 1 ) from RDB$DATABASE
Hibernate: select gen_id( hibernate_sequence, 1 ) from RDB$DATABASE
Hibernate: select gen_id( hibernate_sequence, 1 ) from RDB$DATABASE
Hibernate: insert into ObjetTest (code, label, parent, oid) values (?, ?, ?, ?)
Hibernate: insert into ObjetTest (code, label, parent, oid) values (?, ?, ?, ?)
Hibernate: insert into ObjetTest (code, label, parent, oid) values (?, ?, ?, ?)
Hibernate: update ObjetTest set CHILDREN__=? where oid=?
Hibernate: update ObjetTest set CHILDREN__=? where oid=?
Hibernate: select objettest0_.oid as oid0_0_, children1_.oid as oid0_1_, objettest0_.code as code0_0_, objettest0_.label as label0_0_, objettest0_.parent as parent0_0_, children1_.code as code0_1_, children1_.label as label0_1_, children1_.parent as parent0_1_, children1_.CHILDREN__ as CHILDREN5_0__, children1_.oid as oid0__ from ObjetTest objettest0_ left outer join ObjetTest children1_ on objettest0_.oid=children1_.CHILDREN__ order by objettest0_.oid asc
2007-03-21 14:28:20,589 ERROR : IllegalArgumentException in class: ObjetTest, getter method of property: oid
Exception in thread "main" org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of ObjetTest.oid
   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
   at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:183)
   at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3524)
   at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3240)
   at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
   at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:218)
   at org.hibernate.type.ManyToOneType.disassemble(ManyToOneType.java:163)
   at org.hibernate.cache.StandardQueryCache.put(StandardQueryCache.java:80)
   at org.hibernate.loader.Loader.putResultInQueryCache(Loader.java:2118)
   at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2062)
   at org.hibernate.loader.Loader.list(Loader.java:2020)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
   at Test.main(Test.java:33)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
   ... 16 more


Name and version of the database you are using: Firebird 2.0

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 27, 2007 7:57 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
In QueryLoader.getResultColumnOrRow there is a test :
Code:
else if ( !hasTransform ) {
   return row.length == 1 ? row[0] : row;
}


So when there is a ResultTransformer the method returns an array of size 1 and when there isn't, it returns directly an object.

It seems this is the cause of the problem later with the query cache. I will fill a jira for that

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.