[Hibernate-JIRA] Created: (HHH-2463) ClassCastException when Hibernate tries to cache results using ResultTransformer
by Peak user (JIRA)
ClassCastException when Hibernate tries to cache results using ResultTransformer
--------------------------------------------------------------------------------
Key: HHH-2463
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2463
Project: Hibernate3
Type: Bug
Versions: 3.2.2
Reporter: Peak user
When Hibernate executes a cacheable query using a ResultTransformer, it will attempt to cache the results AFTER applying the ResultTransformer. The problem is that the ResultTransformer may modify the data in a way that Hibernate won't understand it anymore, and in this case it will generate a ClassCastException when trying to cache it.
This problem could be easily solved if Hibernate cached results before applying the ResultTransformer instead of afterwards.
Here's a sample code to reproduce this problem:
class ToMapResultTransformer implements ResultTransformer {
private String[] properties;
public ToMapResultTransformer(String[] properties) {
this.properties = properties;
}
public List transformList(List collection) {
return collection;
}
public Object transformTuple(Object[] tuple, String[] aliases) {
Map<String,Object> result = new HashMap<String,Object>(tuple.length);
for (int i=0; i<tuple.length; i++) {
result.put((properties != null ? properties[i] : aliases[i]), tuple[i]);
}
return result;
}
}
Criteria sqlCriteria = createSqlCriteria(session);
sqlCriteria.setProjection(projections);
sqlCriteria.setCacheable(true);
sqlCriteria.setResultTransformer(new ToMapResultTransformer(properties));
sqlCriteria.list();
The code above produces the following exception:
java.lang.ClassCastException: java.util.HashMap
at org.hibernate.cache.StandardQueryCache.put(StandardQueryCache.java:83)
at org.hibernate.loader.Loader.putResultInQueryCache(Loader.java:2185)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2129)
at org.hibernate.loader.Loader.list(Loader.java:2087)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
16 years, 4 months
[Hibernate-JIRA] Created: (HHH-2525) Bug when using a ResultTransformer on a cached query
by Sebastien Cesbron (JIRA)
Bug when using a ResultTransformer on a cached query
----------------------------------------------------
Key: HHH-2525
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2525
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.2
Environment: Firebird 2.0 on Win XP
Reporter: Sebastien Cesbron
Attachments: testhib.zip
Using a distinct result transformer which a cached like this :
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);
query.list();
This leads to this exception
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
It seems this is due to a difference in QueryLoader.getResultColumnOrRow. In this method there is a test :
else if ( !hasTransform ) {
return row.length == 1 ? row[0] : row;
}
This causes the method to return an instance of ObjetTest in one case and an instance of ObjetTest[1] in the other one. In the latter test, when putting the query into the query cache, hibernate calls the getOid method on an array of ObjetTest and this causes the exception
--
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
16 years, 4 months
[Hibernate-JIRA] Created: (HHH-2299) dynamic-map entity mode mappings with relationships rise lazy initialization during performing query
by Boleslaw Dawidowicz (JIRA)
dynamic-map entity mode mappings with relationships rise lazy initialization during performing query
Created: Yesterday 05:51 AM Updated: Yesterday 06:07 AM
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-2299
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2299
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.1
Reporter: Boleslaw Dawidowicz
Attachments: hibernate-issue.tar.gz
(copied from http://jira.jboss.com/jira/browse/HIBERNATE-51)
(attached IntelliJ project with test case that reproduce this issue)
If I create bidirectional relationship between two dynamic-map entities, commit a transaction and start new session, performing a query to obtain an entity raise LazyInitializationException.
(full intellij project attached)
code and mappings:
public void testSF() throws Exception
{
sf.openSession();
Session es = sf.getCurrentSession();
Transaction tx = es.beginTransaction();
Map lolo = new HashMap();
lolo.put("userName", "lolo");
es.save("PortalUser", lolo);
Map dummy = new HashMap();
dummy.put("name", "dummy");
es.save("PortalRole", dummy);
Set roles = new HashSet();
roles.add(dummy);
lolo.put("roles",roles);
Map props = new HashMap();
props.put("theme", "pp");
props.put("signature", "alalala");
lolo.put("dynamic", props);
es.save("PortalUser", lolo);
tx.commit();
sf.openSession();
es = sf.getCurrentSession();
tx = es.beginTransaction();
Query query = es.createQuery("from PortalUser where userName=:userName");
query.setParameter("userName", "lolo");
//LazyInitializationException on this LINE!!!
lolo = (Map)query.uniqueResult();
assertNotNull(lolo.get("roles"));
assertNotNull(lolo.get("dynamic"));
tx.commit();
}
<hibernate-mapping>
<class
entity-name="PortalUser">
<!--<cache usage="@portal.hibernate.cache.usage@"/>-->
<id
name="key"
column="jbp_uid"
type="java.lang.Long">
<generator class="native">
<param name="sequence">user_seq</param>
</generator>
</id>
<property
name="userName"
column="jbp_uname"
type="java.lang.String"
update="false"
insert="true"
unique="true"/>
<map
name="dynamic"
table="jbp_user_prop"
lazy="false"
sort="unsorted"
cascade="all">
<!--<cache usage="@portal.hibernate.cache.usage@"/>-->
<key column="jbp_uid"/>
<index
column="jbp_name"
type="java.lang.String"/>
<element
column="jbp_value"
type="java.lang.String"
not-null="false"
unique="false"/>
</map>
<!--@mappings@-->
<property
name="password"
column="jbp_password"
type="java.lang.String"
update="true"
insert="true"
unique="false"/>
<set
name="roles"
table="jbp_role_membership"
lazy="false"
inverse="false"
cascade="none"
sort="unsorted">
<!--<cache usage="@portal.hibernate.cache.usage@"/>-->
<key column="jbp_uid"/>
<many-to-many
entity-name="PortalRole"
column="jbp_rid"
outer-join="true"/>
</set>
</class>
<class
entity-name="PortalRole"
table="jbp_roles">
<!--<cache usage="@portal.hibernate.cache.usage@"/>-->
<id
name="key"
column="jbp_rid"
type="java.lang.Long">
<generator class="native">
<param name="sequence">user_seq</param>
</generator>
</id>
<property
name="name"
column="jbp_name"
type="java.lang.String"
update="false"
insert="true"
unique="true"/>
<property
name="displayName"
column="jbp_displayname"
type="java.lang.String"
update="true"
insert="true"
unique="true"/>
<set
name="users"
table="jbp_role_membership"
lazy="true"
inverse="true"
cascade="none"
sort="unsorted">
<!--<cache usage="@portal.hibernate.cache.usage@"/>-->
<key column="jbp_rid"/>
<many-to-many
entity-name="PortalUser"
column="jbp_uid"
outer-join="false"/>
</set>
</class>
</hibernate-mapping>
Stack trace:
org.hibernate.LazyInitializationException: illegal access to loading collection
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:341)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentSet.hashCode(PersistentSet.java:411)
at java.util.HashMap$Entry.hashCode(HashMap.java:764)
at java.util.AbstractMap.hashCode(AbstractMap.java:557)
at java.util.HashMap.put(HashMap.java:418)
at java.util.HashSet.add(HashSet.java:194)
at java.util.AbstractCollection.addAll(AbstractCollection.java:318)
at org.hibernate.collection.PersistentSet.endRead(PersistentSet.java:329)
at org.hibernate.engine.CollectionLoadContext.endLoadingCollection(CollectionLoadContext.java:183)
at org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:268)
at org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:249)
at org.hibernate.loader.Loader.endCollectionLoad(Loader.java:866)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:853)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1985)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentSet.hashCode(PersistentSet.java:411)
at java.util.HashMap$Entry.hashCode(HashMap.java:764)
at java.util.AbstractMap.hashCode(AbstractMap.java:557)
at java.util.HashMap.put(HashMap.java:418)
at java.util.HashSet.add(HashSet.java:194)
at java.util.AbstractCollection.addAll(AbstractCollection.java:318)
at org.hibernate.collection.PersistentSet.endRead(PersistentSet.java:329)
at org.hibernate.engine.CollectionLoadContext.endLoadingCollection(CollectionLoadContext.java:183)
at org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:268)
at org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:249)
at org.hibernate.loader.Loader.endCollectionLoad(Loader.java:866)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:853)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1985)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:755)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:229)
at org.hibernate.loader.Loader.doList(Loader.java:2211)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:388)
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 org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:804)
at org.jboss.test.DynamicTest.testSF(DynamicTest.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
also note that commenting out this 3 lines makes it work:
Set roles = new HashSet();
roles.add(dummy);
lolo.put("roles",roles);
So I guess it's about resolving roles relationship during obtaing a user object
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
16 years, 5 months
[Hibernate-JIRA] Created: (HBX-910) hbm2ddl doesn't create identity column with custom identifier generator
by Luca Dall'Olio (JIRA)
hbm2ddl doesn't create identity column with custom identifier generator
-----------------------------------------------------------------------
Key: HBX-910
URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-910
Project: Hibernate Tools
Type: Bug
Environment: hibernate 3.2.1 hsqldb 8.0.1
Reporter: Luca Dall'Olio
Priority: Minor
When defining a custom identifiergenerator which implements org.hibernate.id.PostInsertIdentifierGenerator ,
hbm2ddl doesn't define the primary key column as identity (i.e. hibernate.hbm2ddl.auto=create)
By looking at the source code, the hbm2dll depends on org.hibernate.mapping.SimpleValue.isIdentityColumn() function, which in turn has a direct dependency on IdentityGenerator.class :
public boolean isIdentityColumn(Dialect dialect) {
return IdentifierGeneratorFactory.getIdentifierGeneratorClass(identifierGeneratorStrategy, dialect)
.equals(IdentityGenerator.class);
}
in my opinion, it should depend instead on the PostInsertIdentifierGenerator interface :
public boolean isIdentityColumn(Dialect dialect) {
return IdentifierGeneratorFactory.getIdentifierGeneratorClass(identifierGeneratorStrategy, dialect)
.isInstance(PostInsertIdentifierGenerator.class);
}
Here is an example of a custom IdentityGenerator which can reproduce this problem :
package sample;
...
public class CustomIdentifierGenerator implements IdentifierGenerator, PostInsertIdentifierGenerator {
private static IdentityGenerator hibernateGeneratorDelegate = null;
public Serializable generate(SessionImplementor session, Object object)
throws HibernateException {
return hibernateGeneratorDelegate.generate(session, object);
}
public InsertGeneratedIdentifierDelegate getInsertGeneratedIdentifierDelegate(
PostInsertIdentityPersister persister, Dialect dialect,
boolean isUseGet) throws HibernateException {
return hibernateGeneratorDelegate.getInsertGeneratedIdentifierDelegate(persister, dialect, isUseGet);
}
}
Here an example mapping fragment :
<id name="id" type="long" column="DMM_ID">
<generator
class="sample.CustomIdentifierGenerator " />
</id>
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
16 years, 5 months